Thread state
A thread can exist in a number of different states. The various states of a thread are shown in the picture below:All the states of the thread are briefly discussed below:
i. Blocked:
A thread is said to be blocked that has suspended execution because it is waiting to acquire a lock.ii. New:
A thread that hasn’t begun execution.iii. Runnable:
A thread that either is currently executing or will execute when it gains access to CPU.iv. Terminated:
A thread that has completed execution.v. Timed-waiting:
A thread that has suspended execution for a specified period of time such as it has called sleep. This state is also entered when a timed version of wait or join is called.vi. Waiting:
A thread that has suspended execution because it is waiting for some action to occur. For example, it is waiting because of a call to a non-timed out version of wait or join.We can obtain the current state of the thread by calling the getstate() method defined by thread.
Thread.State getstate()
No comments:
Post a Comment