What is the life cycle of Thread ?

Answers were Sorted based on User's Feedback



What is the life cycle of Thread ?..

Answer / chinnadurai

1. when the thread create New State
2. after start() Runnable state
3. Running State
4. Wait/Block/Sleep State
5. Dead State

Is This Answer Correct ?    79 Yes 11 No

What is the life cycle of Thread ?..

Answer / harish

Once you create a Thread Class. Instantiate the Thread and
invoke the method start. It intern triggers the run method
on the Thread. Once the run method is completed, The
thread will be in dead state.

Is This Answer Correct ?    53 Yes 20 No

What is the life cycle of Thread ?..

Answer / shajin.a.xavier

Ready-to-run
A thread starts its life cycle with a call to start(). For
example

MyThread aThread = new MyThread();
aThread.start();

A call to start() will not immediately start thread's
execution but rather will move it to pool of threads
waiting for their turn to be picked for execution. The
thread scheduler picks one of the ready-to-run threads
based on thread priorities.
Running
The thread code is being actively executed by the
processor. It runs until it is swapped out, becomes
blocked, or voluntarily give up its turn with this static
method
Thread.yield();

Please note that yield() is a static method. Even if it is
called on any thread object, it causes the currently
executing thread to give up the CPU.
Waiting
A call to java.lang.Object's wait() method causes the
current thread object to wait. The thread remains
in "Waiting" state until some another thread invokes notify
() or the notifyAll() method of this object. The current
thread must own this object's monitor for calling the wait
().
Sleeping
Java thread may be forced to sleep (suspended) for some
predefined time.

Thread.sleep(milliseconds);
Thread.sleep(milliseconds, nanoseconds);

Please note that static method sleep() only guarantees that
the thread will sleep for predefined time and be running
some time after the predefined time has been elapsed.
For example, a call to sleep(60) will cause the currently
executing thread to sleep for 60 milliseconds. This thread
will be in ready-to-run state after that. It will be
in "Running" state only when the scheduler will pick it for
execution. Thus we can only say that the thread will run
some time after 60 milliseconds.
Blocked on I/O.
A java thread may enter this state while waiting for data
from the IO device. The thread will move to Ready-to-Run
after I/O condition changes (such as reading a byte of
data).
Blocked on Synchronization.
A java thread may enter this state while waiting for object
lock. The thread will move to Ready-to-Run when a lock is
acquired.
Dead
A java thread may enter this state when it is finished
working. It may also enter this state if the thread is
terminated by an unrecoverable error condition.

Is This Answer Correct ?    32 Yes 3 No

What is the life cycle of Thread ?..

Answer / sasikala d

1. 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.
2. 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.
3. 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.
4. 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.
5. Blocked - A thread can enter in this state because
of waiting the resources that are hold by another thread.

Is This Answer Correct ?    16 Yes 2 No

What is the life cycle of Thread ?..

Answer / shajin.a.xavier

Multithreading is the mechanism in which more than one
thread run independent of each other within the process.
wait (), notify () and notifyAll() methods can be used for
inter-thread communication and these methods are in Object
class. wait() : When a thread executes a call to wait()
method, it surrenders the object lock and enters into a
waiting state. notify() or notifyAll() : To remove a thread
from the waiting state, some other thread must make a call
to notify() or notifyAll() method on the same object.

Is This Answer Correct ?    16 Yes 6 No

What is the life cycle of Thread ?..

Answer / dhirendra kumar sharma

These are the life cycle of Thread.-------------
I) New thread
II) Runnable
III) Not runnable
IV) Dead

Is This Answer Correct ?    13 Yes 7 No

What is the life cycle of Thread ?..

Answer / ravikiran

start
run
destroy are the methods

born
runnable
running
sleep/blocked
dead are the states

Is This Answer Correct ?    12 Yes 7 No

What is the life cycle of Thread ?..

Answer / vaibhav mistry

The cycle of Thread is as Followed :

Start()
Run()
Wait()/Sleep()/Block()
notify()/notifyall()
Stop()

Is This Answer Correct ?    7 Yes 4 No

What is the life cycle of Thread ?..

Answer / harmeet

1.create the thread on which object u want, using Thread
interface,
2.then use obj.start() to invoke the thread
3.this method will intern call run() of Thread class
4.once it's serviced, it will come to dead state.

Is This Answer Correct ?    18 Yes 16 No

What is the life cycle of Thread ?..

Answer / karnika

The following diagram shows the states that a Java thread
can be in during its life. It also illustrates which method
calls cause a transition to another state. This figure is
not a complete finite state diagram, but rather an overview
of the more interesting and common facets of a thread's
life. The remainder of this section uses the Clock applet
previously introduced to discuss a thread's life cycle in
terms of its state.

Is This Answer Correct ?    2 Yes 0 No

Post New Answer

More Core Java Interview Questions

Is static a singleton?

0 Answers  


Explain different forms of polymorphism?

0 Answers  


What is a substring of a string?

0 Answers  


Are the equals() and hashCode() protected methods of object class?

1 Answers   Avaya,


How can we make string upper case or lower case?

0 Answers  






How do you avoid global variables?

0 Answers  


Why can't we override private static methods?

0 Answers  


Explain the term virtual machine?

0 Answers   Adobe,


What is void class in java?

0 Answers  


What are checked exceptions?

0 Answers  


What is the difference between the final method and abstract method?

0 Answers  


Any one can explain how the inerface uses in java. give with example.

1 Answers   IBM,


Categories