Monday, 13 March 2017

Java: Different Thread States

A Thread in java can be in 5 states

1. new
2. runnable
3. running
4. blocked/waiting/sleeping
5. dead

Some points to remember:

1. When a thread is dead, it can never be restarted even if it's still a valid object on the heap.
2. There is only 1 way a thread can transition to running, and that's from runnable.
3. Once running, a thread can become dead, go to sleep, wait for another thread to finish, block on an object's lock, wait for a notification, or return to runnable.

0 comments:

Post a Comment

Note: only a member of this blog may post a comment.