ALLInterview.com :: Home Page            
 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                      
Google
   
 
Categories >> Software >> Java Related >> Java J2EE >> Core Java
 
 


 

 
 Core Java interview questions  Core Java Interview Questions (1720)
 Advanced Java interview questions  Advanced Java Interview Questions (331)
 Swing interview questions  Swing Interview Questions (43)
 EJB interview questions  EJB Interview Questions (134)
 Servlets interview questions  Servlets Interview Questions (255)
 Struts interview questions  Struts Interview Questions (195)
 JDBC interview questions  JDBC Interview Questions (187)
 JMS interview questions  JMS Interview Questions (9)
 SunOne interview questions  SunOne Interview Questions (3)
 J2EE interview questions  J2EE Interview Questions (71)
 Weblogic interview questions  Weblogic Interview Questions (145)
 Websphere interview questions  Websphere Interview Questions (14)
 Java Networking interview questions  Java Networking Interview Questions (20)
 Java J2EE AllOther interview questions  Java J2EE AllOther Interview Questions (87)
Question
explain the life cycle of thread?
 Question Submitted By :: Venu
I also faced this Question!!     Rank Answer Posted By  
 
  Re: explain the life cycle of thread?
Answer
# 1
There are number of stages for executing the Thread.
1.ready to run
2.run
3.suspend(wait,sleep)
4.resume(notify,notify all)
5.kill.
 
Is This Answer Correct ?    62 Yes 26 No
Ganesh
 
  Re: explain the life cycle of thread?
Answer
# 2
There are number of stages for executing the Thread.
1.born state
2.runnable
3.running(wait,sleep)
4.blocked(wait,sleep)
5.destroy.
 
Is This Answer Correct ?    44 Yes 21 No
Srinivas
 
 
 
  Re: explain the life cycle of thread?
Answer
# 3
There are number of stages for executing the Thread.
1.born state
2.runnable
3.running
4.blocked(wait,sleep,suspend)
5.destroy(stop).
 
Is This Answer Correct ?    27 Yes 12 No
Srinivas Ponugoti
 
  Re: explain the life cycle of thread?
Answer
# 4
b/c in every program at least one thread automically involve 
Is This Answer Correct ?    12 Yes 17 No
Jetender
 
  Re: explain the life cycle of thread?
Answer
# 5
The thread states are:

- New (created but start mtd not called)
- Runnable (Ready to run, waiting for CPU cycles)
- Running (allocated CPU cycle)
- Suspended (timed sleeping)
- Wait (waiting for a notify)
- Stopped (Completed)
 
Is This Answer Correct ?    38 Yes 4 No
Vazza Jones
 
  Re: explain the life cycle of thread?
Answer
# 6
1) new bron state
2) runnable state
3) running state
4) blocked state
5) dead state
 
Is This Answer Correct ?    22 Yes 2 No
Rakesh
 
  Re: explain the life cycle of thread?
Answer
# 7
Thread : A Thread is a saparate path between ur source code
to execution .
it have
new , ready ,running , dispatch , stop
 
Is This Answer Correct ?    8 Yes 5 No
Manoj Kumar
 
  Re: explain the life cycle of thread?
Answer
# 8
There are five states New,Runnable,Running,Blocked,Dead

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 the 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.
 
Is This Answer Correct ?    30 Yes 2 No
God&039;y
 
  Re: explain the life cycle of thread?
Answer
# 9
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 ?    7 Yes 3 No
Nishant S Mevawala
 
  Re: explain the life cycle of thread?
Answer
# 10
1 Newborn State

2 Runnable State

3 Running State

4 Blocked State

5 Dead State
1 Newborn State

When we create a thread it will be in Newborn State.

The thread is just created still its not running.

We can move it to running mode by invoking the start() method and it can be killed by using stop() method.
2 Runnable State

It means that thread is now ready for running and its waiting to give control.

We can move control to another thread by yield() method.

3 Running State

It means thread is in its execution mode becaause the control of cpu is given to that particular thread.

It can be move in three different situation from running mode.
These all are different methods which can be apply on running thread and how the state is changing and how we can come in our original previous state using different methods are shown in above figure.

4 Blocked State

A thread is called in Blocked State when it is not allowed to entering in Runnable State or Running State.

It happens when thread is in waiting mode, suspended or in sleeping mode.

5 Dead State

When a thread is completed executing its run() method the life cycle of that particular thread is end.

We can kill thread by invoking stop() method for that particular thread and send it to be in Dead State.
 
Is This Answer Correct ?    1 Yes 0 No
Dinesh Kumar
 

 
 
 
Other Core Java Interview Questions
 
  Question Asked @ Answers
 
Why sleep()is in Thread and wait() in Object class? Why can't I have both in one class or vice versa?   1
explain about jre and jvm   2
what is diff bet iterator and enumeration?   4
why java does not support mulitple inheritance directly? TCS 2
How many types of JVM's (OR) Name of the JVM's which are used in Tomcat & Weblogic servers ? TCS 1
what is prepare statement? what is calabedtarement? Symphony 1
Can you extend more than one interface?   9
What is the difference between parameters and arguments ?   2
How do you relate a Interface to a Class? Tell me in Detail?   4
Convert a binary search tree to a sorted doubly linked list inplace. Amazon 1
Difference between flush() and commit() in hibernate? Bally-Technologies 2
What is a compilation unit?   2
 
For more Core Java Interview Questions Click Here 
 
 
 
 
 


   
Copyright Policy  |  Terms of Service  |  Articles  |  Site Map  |  RSS Site Map  |  Contact Us
   
Copyright 2013  ALLInterview.com.  All Rights Reserved.

ALLInterview.com   ::  KalAajKal.com