LIFE CYCLE OF A THREAD
During the life cycle of a thread there are many states. It can enter them include :--
1.New born state.
2.Runnable state.
3.Running state.
4.Blocked state.
5.Dead state.
1.New born state : When we create a thread object the thread is born and is said to be new born state. At this state we can do only one of the following thinks with it.
a. Schedule it for running using start () method.
b. Kill it using state method.
2.Runnable state : Rub able state means that the thread is ready for execution and it waiting for the availability of the processor. Thread has joined the queue of threads that are waiting for execution. If all threads have equal priority then they are given time slots for execution in round rooming fashion that is fast come fast surp manner.
However if you want a thread to a relinquishing control to another thread of equal priority before its turn common we can do by using yield method.
3.Running state : Running means that the processor has given it’s time to the thread for its execution. The thread runs until if relinquishes control on its own or it is primitive by a higher priority thread. A running thread may relinquish its control in one of the following situation.
a. It has been suspended using suspend() a suspended thread can be revived by using the resume() method. This approach is useful when we want to suspend a thread for some time due to carton resume but don’t to kill it.
b. It has been made to sleep. We can put a thread to sleep for a specifying time period using the method(time) where time is an milliseconds this means that the thread is out the queue during the time period.
c. It has been told to wait until same even occur. This is done using the wait method. The thread can be scheduling to run again using the notify() method.
4.Block state : A thread is said to be block when it is prevented from entering into the ‘Runable’ state and sub sequently the running state. This happen when the thread is suspended, sleeping, waiting in order to satisfy curtain requirements.
5.Dead state : Every threads has a life cycle. A running thread ends its life when it has completed executing its run() method. It is a neutral death. We can kill it by sending the stop message to it at any states thus causing a premature dead to it.
No comments :
Post a Comment