answersLogoWhite

0


Best Answer

One is more important than the other

User Avatar

Wiki User

12y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: What is the difference between runnable state and running state of thread in java?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Statistics
Related questions

Life cycle of thread in java?

# New state - After the creations of Thread instance the thread is in this state but before the start() method invocation. At this point, the thread is considered not alive.# Runnable (Ready-to-run) state - A thread start its life from Runnable state. A thread first enters runnable state after the invoking of start() method but a thread can return to this state after either running, waiting, sleeping or coming back from blocked state also. On this state a thread is waiting for a turn on processor. # Running state - A thread is in running state that means the thread is currently executing. There are several ways to enter in Runnable state but there is only one way to enter in Running state: the scheduler select a thread from runnable pool.# Dead state - A thread can be considered dead when its run() method completes. If any thread comes on this state that means it cannot ever run again. # Blocked - A thread can enter in this state because of waiting the resources that are hold by another thread.


Multithreading in java?

I am assuming that you want to know how to multithread in Java. 1) Write a class that implements Runnable. Put just the method run() in it. 2) Inside the run() method, put the code that you want your thread to run. 3) Instantiate the class (example: Runnable runnable = new MyRunnable();) 4) Make a new Thread (example: Thread thread = new Thread(runnable, <the name of your thread(optional)>); 5) Start the thread (example: thread.start();) 6) That's it! Your thread is now running. PS. Check the Java API for more information. Did that answer your question?


Why do you need runnable interface?

A Runnable Interface is one that is used to create a Java Thread... A Thread can be created in two ways and using the Runnable Interface is one of them. Example: public class Test implements Runnable { public void run(){ .... } } The Runnable interface would have an abstract instance of the method run() which needs to be implemented in the class which wants to create a Thread.


What are the different ways of implementing thread in java?

You can define and instantiate a thread in one of two ways: • Extend the java.lang.Thread class. • Implement the Runnable interface. class MyFirstThread extends Thread { public void run() { System.out.println("Important job running in MyFirstThread"); } } or class MyFirstRunnableClass implements Runnable { public void run() { System.out.println("Imp job running in MyFirstRunnableClass"); } }


How do you make a Thread in java?

You can define and instantiate a thread in one of two ways: • Extend the java.lang.Thread class. • Implement the Runnable interface. Ex: class MyFirstThread extends Thread { public void run() { System.out.println("Important job running in MyFirstThread"); } } class MyFirstRunnableClass implements Runnable { public void run() { System.out.println("Imp job running in MyFirstRunnableClass"); } }


Describe a simple scheme in which there are as many lightweight processes as there are runnable threads?

Start with only a single LWP and let it select a runnable thread. When arunnable thread has been found, the LWP creates another LWP to look for anext thread to execute. If no runnable thread is found, the LWP destroys itself.


How can you create threads in Java?

You can create threads by two ways in Java:By extending the Thread class orBy implementing the Runnable interface.Ex:class MyFirstThread extends Thread {public void run() {System.out.println("Important job running in MyFirstThread");}}orclass MyFirstRunnableClass implements Runnable {public void run() {System.out.println("Imp job running in MyFirstRunnableClass");}}


What are various ways to create a thread in java?

You can define and instantiate a thread in one of two ways: • Extend the java.lang.Thread class. • Implement the Runnable interface. Ex: class MyFirstThread extends Thread { public void run() { System.out.println("Important job running in MyFirstThread"); } } class MyFirstRunnableClass implements Runnable { public void run() { System.out.println("Imp job running in MyFirstRunnableClass"); } }


If Runnable interface is better than Thread class than why you are using Thread class What is the need for Thread class?

Though implementing Runnable interface is better approach than inheriting from Thread class but there are certain methods available in Thread class like join,sleep or yield which does not available in Runnable interface and programmer can not use them unless he has object of Thread class. This is why we should have Thread class Object. Rupesh Raghani


Describe the Life cycle of a thread in java.?

Life cycle of a thread New: when a thread is not yet initialized, it is in New state Runnable or Ready : Once the thread is initialized and its start method is called, then the thread becomes ready for execution, which is otherwise called runnable or ready state Not Runnable : When a thread is asked to sleep for some time or wait for some time by using the sleep or wait method, thread goes to Not Runnable state for the specified time. Dead state: Once the thread is executed,it turns to dead state. Hope this would answer your question. let me know if you are still not clear


Write an algorithm for Round Robin CPU scheduling using?

On each system clock tick, at interval set by design...If no other runnable threads, return from clock interrupt.Save the currently running thread's context.Restore the next runnable thread's context.Return from clock tick interrupt.Note: Most modern schedulers combine round-robin with priority. In the priority scheme, any runnable thread with a higher priority than the interrupted thread takes precedence. If there are none, then round-robin applies at the current priority. If there are no runnable threads at the current priority, lower priorities are considered until we reach the idle priority thread, which, by the way, is always runnable.Also, there is usually an algorithm that adjusts thread priority dynamically. As the thread runs, if it stays runnable its priority slowly drops from its initial base priority. If it is constantly blocking and then then becoming runnable, its priority increases, often faster than it decreases. This makes interactive threads appear to be very responsive, while CPU intensive threads slowly defer to interactive threads. This is usually a good compromise between responsiveness and throughput.


What are the two ways of spawning a thread in Java?

You can create a Thread in Java by using two ways. 1. Extending the Thread class public class Test extends Thread { ..... } 2. Implementing the Runnable Interface public class Test implements Runnable { ... }