Summary
Here are the methods we introduced in this chapter:
- void wait()
Waits for a condition to occur. This is a method of the Object class and must be called from within a synchronized method or block.
- void wait(long timeout)
Waits for a condition to occur. However, if the notification has not occurred in
timeoutmilliseconds, it returns anyway. This is a method of the Object class and must be called from a synchronized block or method.- void wait(long timeout, int nanos)
Waits for a condition to occur. However, if the notification has not occurred in
timeoutmilliseconds and nanos nanoseconds, it returns anyway. This is a method of the Object class and must be called from a synchronized block or method.- void notify()
Notifies a thread that is waiting for a condition that the condition has occurred. This is a method of the Object class and must be called from within a synchronized method or block.
- void notifyAll()
Notifies all the threads waiting on the object that the condition has occurred. This is a method of the Object class and must be called from within a synchronized method or block.
- void interrupt() (Java 1.1 and above only)
Sends an interruption to the specified thread. If the thread is currently blocked in a thread-related method (i.e., the
sleep(),join(), orwait()methods), the thread moves to an unblocked state; otherwise, a boolean flag is simply set to indicate that the thread has been interrupted.- static boolean interrupted() (Java 1.1 and above only)
Returns a ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access