Sunday 2 March 2014

Thread wait

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

Object class has 3 overloaded variations of wait method.

public final void wait() throws InterruptedException
Causes current thread to wait until another thread invokes the notify() method or the notifyAll() method for this object. To call the wait(), current thread must get Objects monitor, other wise IllegalMonitorStateException thrown.

When wait called on particular object, The thread releases ownership of this monitor and waits until another thread notifies threads waiting on this object's monitor to wake up either through a call to the notify method or the notifyAll method.

public final void wait(long timeout) throws InterruptedException
Causes current thread to wait until either another thread invokes the notify() method or the notifyAll() method for this object, or a specified amount of time has elapsed.

public final void wait(long timeout, int nanos)throws InterruptedException

Causes current thread to wait until another thread invokes the notify() method or the notifyAll() method for this object, or some other thread interrupts the current thread, or a certain amount of real time has elapsed.



Producer Consumer Problem                                                 Notify thread                                                 Home

No comments:

Post a Comment