Waiting/blocked/sleeping Running thread stage

Waiting/blocked/sleeping Running thread stage

The thread may be blocked waiting for a resourcein which case the event that sends it back to runnable is the availability of the resource for example, if data comes in through the input stream the thread code is reading from, or if the object\'s lock suddenly becomes available.A thread may be sleeping because the thread\'s run code tells it to sleep for some period of time, in which case the event that sends it back to runnable is that it wakes up because its sleep time has expired. Or the thread may be waiting, because the thread\'s run code causes it to wait, in which case the event that sends it back to runnable is that another thread sends a notification that it may no longer be necessary for the thread to wait. 

The important point is that one thread does not tell another thread to block. There is a method, suspend(), in the Thread class, that lets one thread tell another to suspend, but the suspend()method has been deprecated and won\'t be on the exam (nor will its counterpart resume()). There is also a stop() method, but it too has been deprecated and we won\'t even go there. Both suspend() and stop() turned out to be very dangerous.

By:umang
Date:2017-03-09 00:00:00

Post Your Answers


User Email:

User Name:
Answers:

Related scjp1.5 chap10 Links

scjp1.5 chap10 interview questions and answers for experienced and fresher