Home » Java Thread notify() Method with Examples

Java Thread notify() Method with Examples

by Online Tutorials Library

Java Thread notify() method

The notify() method of thread class is used to wake up a single thread. This method gives the notification for only one thread which is waiting for a particular object.

If we use notify() method and multiple threads are waiting for the notification then only one thread get the notification and the remaining thread have to wait for further notification.

Syntax

Return

This method does not return any value.

Exception

IllegalMonitorStateException: This exception throws if the current thread is not the owner of the object’s monitor.

Example

Output:

Starting of Thread-1 Starting of Thread-2 Starting of Thread-3 Thread-3...notified Thread-1...notified 

You may also like