Basic HTML version of Foils prepared 17 Nov 97

Foil 11 Synchronization is Implemented by Monitors

From Java Tutorial, July 1, 1996 CEWES Tutorial, CPS606, JSU Class CSC499 -- July 22-25 1997, Fall 97. by Nancy J. McCracken,Geoffrey C. Fox, Tom Scavo


An object that can block threads and notify them when it is available is called a monitor. A monitor is associated with an instance of the class; it has a lock and a queue.
If a class has one or more synchronized methods, each object (instance) of the class has a monitor. The queue holds all threads waiting to execute a synchronized method.
  • A thread enters the queue by calling wait() inside the method or when another thread is already executing the method.
  • When a synchronized method returns, or when a method calls wait(), another thread may access the object.
  • As always, the scheduler chooses the highest-priority thread among those in the queue.
  • If a thread is put into the queue by calling wait(), it can't be scheduled for execution until some other thread calls notify().



© Northeast Parallel Architectures Center, Syracuse University, npac@npac.syr.edu

If you have any comments about this server, send e-mail to webmaster@npac.syr.edu.

Page produced by wwwfoil on Wed Apr 1 1998