Skip to main content

Posts

Showing posts from December, 2008

Thread Communication

thread communication deals the problem that if one thread leaves the monitor then how it will tell to the waiting thread that it is now free to get the monitor. java provide interprocess communication machenism through wait() ,notify() and notifyAll() methods. these method are implemented in the object class as final. notify() It called by the monitor owner thread to wakes up a single thread that is waiting for this monitor object. If more then one, threads are waiting for this monitor then one of them is chosen to be awakened. The choice is arbitrary. notifyAll() It called by the monitor owner thread to wakes up multiple threads waiting for this monitor object. wait() Causes current thread to wait until another thread invokes the notify () method or the notifyAll() method for this object. It throws InterruptedException wait(long timeout)                Causes current thread to wait until either another thread invokes the notify() method or the notifyAll() method for this object, o