Sunday, July 4, 2010

Inter-thread Communication

Java includes an interprocess communication mechanism via the wait( ), notify( ), and notifyAll( ) methods. These methods are implemented as final methods in Object, so all classes have them. All three methods can be called only from within a synchronized context.


• wait( ) tells the calling thread to give up the monitor and go to sleep until some other thread enters the same monitor and calls notify( ).

• notify( ) wakes up the first thread that called wait( ) on the same object.

• notifyAll( ) wakes up all the threads that called wait( ) on the same object. The highest priority thread will run first.

No comments:

Post a Comment