Java Programming - Threads - Discussion

Discussion Forum : Threads - General Questions (Q.No. 13)
13.
Which of the following will not directly cause a thread to stop?
notify()
wait()
InputStream access
sleep()
Answer: Option
Explanation:

Option A is correct. notify() - wakes up a single thread that is waiting on this object's monitor.

Option B is wrong. wait() causes the current thread to wait until another thread invokes the notify() method or the notifyAll() method for this object.

Option C is wrong. Methods of the InputStream class block until input data is available, the end of the stream is detected, or an exception is thrown. Blocking means that a thread may stop until certain conditions are met.

Option D is wrong. sleep() - Causes the currently executing thread to sleep (temporarily cease execution) for a specified number of milliseconds. The thread does not lose ownership of any monitors.

Discussion:
3 comments Page 1 of 1.

Rafael said:   1 decade ago
This is not entirely true: I can write my own InputStream which might e.g. only provide mock data. This would not cause a thread to stop.

Chandan Shankar said:   7 years ago
Yes, agree @Rafael.

Raj said:   6 years ago
Please anyone can explain this?

Post your comments here:

Your comments will be displayed after verification.