ALLInterview.com :: Home Page KalAajKal.com
 Advertise your Business Here     
Browse  |   Placement Papers  |   Company  |   Code Snippets  |   Certifications  |   Visa Questions
Post Question  |   Post Answer  |   My Panel  |   Search  |   Articles  |   Topics  |   ERRORS new
   Refer this Site  Refer This Site to Your Friends  Site Map  Bookmark this Site  Set it as your HomePage  Contact Us     Login  |  Sign Up                      
tip       Ask Questions on ANYTHING, that arise in your Daily Life at     FORUM9.COM
Google
 
Categories  >>  Software  >>  Core Java  >>  Java J2EE  >>  Java Related
 
 


 

 
 Core Java interview questions  Core Java Interview Questions
 Advanced Java interview questions  Advanced Java Interview Questions
 Swing interview questions  Swing Interview Questions
 EJB interview questions  EJB Interview Questions
 Servlets interview questions  Servlets Interview Questions
 Struts interview questions  Struts Interview Questions
 JDBC interview questions  JDBC Interview Questions
 JMS interview questions  JMS Interview Questions
 SunOne interview questions  SunOne Interview Questions
 J2EE interview questions  J2EE Interview Questions
 Weblogic interview questions  Weblogic Interview Questions
 Websphere interview questions  Websphere Interview Questions
 Java Networking interview questions  Java Networking Interview Questions
 Java J2EE AllOther interview questions  Java J2EE AllOther Interview Questions
Question
What is the life cycle of Thread ?
 Question Submitted By :: Harish
I also faced this Question!!     Rank Answer Posted By  
 
  Re: What is the life cycle of Thread ?
Answer
# 1
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 ?    12 Yes 2 No
Harish
 
  Re: What is the life cycle of Thread ?
Answer
# 2
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 ?    20 Yes 1 No
Chinnadurai
 
 
 
  Re: What is the life cycle of Thread ?
Answer
# 3
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 ?    6 Yes 2 No
Harmeet
 
  Re: What is the life cycle of Thread ?
Answer
# 4
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 ?    4 Yes 0 No
Shajin.a.xavier
 
  Re: What is the life cycle of Thread ?
Answer
# 5
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 ?    2 Yes 1 No
Shajin.a.xavier
 
  Re: What is the life cycle of Thread ?
Answer
# 6
start
run
destroy  are the methods

born 
runnable
running
sleep/blocked
dead          are the states

 
Is This Answer Correct ?    4 Yes 2 No
Ravikiran
 
  Re: What is the life cycle of Thread ?
Answer
# 7
Born state.
Running state.
Idle state.
Dead state.
 
Is This Answer Correct ?    0 Yes 1 No
Venkat
 

 
 
 
Other Core Java Interview Questions
 
  Question Asked @ Answers
 
write java code to print second max number in the array Huawei9
What is a void return type?  2
real time example for deadlock,starvation,livelock  4
What is the USE of Null interfaces ??...if thers nothing inside these interfaces how are they used and WHy are they used ???? No 1 has given a proper description yet  1
how can we synchronize Hash map? CTS3
What are other modifiers? Wipro1
Why java Don't Support Multiple interitence ABC7
How are Observer and Observable used?  2
What is means by DLL file means ? What is the use of DLL file? What are the contents of DLL file?  2
How many bits are used to represent unicodde,ASCII,UTF-16 and UTF-8 characters?  2
What classes of exceptions, thrown by a throw statement?  2
How multipleInheritance is possible in java? Satyam16
When will we use class loader?  1
What is advantage of using threads? BMC2
Package1 and Package2 both have a method name lets say "methodA" with different implementation. When I import both the packages in a java class how can I use both the methods? Ericsson3
Can an object be garbage collected while it is still reachable?  2
What is meant by controls and types?  1
What is the difference between this() and super()? TCS11
Howmany address lines are required to addressing 1 MB memory?  2
If there is no implementation of MARKER INTERFACE in java. Then how compiler come to know about specification.  2
 
For more Core Java Interview Questions Click Here 
 
 
 
 
 
   
Copyright Policy  |  Terms of Service  |  Help  |  Site Map 1  |  Articles  |  Site Map  |   Site Map  |  Contact Us interview questions urls   External Links 
   
Copyright © 2007  ALLInterview.com.  All Rights Reserved.

ALLInterview.com   ::  Forum9.com   ::  KalAajKal.com