Implementing Thread Life Cycle

By: Jesse Miller

The life cycle of a thread starts when an object of the System. Threading.Thread class is created. The life cycle of the thread ends with task execution. There are various states in the life cycle of a thread. These states are the Unstarted state, the Runnable state, the Not Runnable state, and the dead state.

When an instance of the Thread class is created, the thread enters the unstarted state. A new thread is an empty object of the Thread class, and no system resources such as memory are allocated to it. To start the thread, Start () should be invoked.

The thread remains in the unstarted state until the program calls the Start () method of the Thread class, which places the thread in the runnable state and immediately returns control to the calling thread. This state is also called as the ready or started state. The newly started thread and any other threads in the program execute concurrently.

A single processor cannot execute more than one thread immediately at a time. Therefore, it maintains a thread queue. When a thread is started, a thread is queued up for the processor time and waits for its turn to get executed. As a result, the state of the thread is said to be runnable and not running.

A thread is not in the runnable state if it is sleeping, waiting, and blocked. A thread is put into the sleeping mode by calling the Sleep () method. A sleeping thread enters the runnable state after the specified time of sleep has elapsed.

Q thread can be made to wait for some specified condition to be satisfied by calling the Wait () method. The thread can be notified of the condition by invoking the Pulse () method of the Thread class. A thread could be blocked by an Input and Output operation.

When the thread is blocked, it enters the not runnable state. A running thread enters the dead state when the statements of the threads method are complete. This state is also called the terminated state.

Quick Note: Taking the Nonsense out of looking for the right spyware remover

If you really want to take the work out of looking for that right Spyware Protection from a go to the Internet and get a or a Free
Download, In order to prevent your vital information from being ripped from your computer get your Remover Today.

A program can force a thread into the dead state by calling the Abort () method of the Thread class on the appropriate thread object. The Abort () method throws a Thread Abort Exception in the thread, normally causing the thread to terminate. The garbage collector can remove the thread object from memory only in the dead state

Computers
 • 
 • 
 • 
 • 
 • 
 • 
 • 
 • 
 • 
 • 
 • 
 • 
 • 
 • 
 • 
 • 
 • 
 • 
 • 
 • 

» More on Computers