Mutual Exclusion in Java
Mutexes and condition variables are built in to every Java object.
- no explicit classes for mutuxes and condition variables
Every object is/has a “monitor”.
- At most one thread may “own” any given object’s monitor.
- A thread becomes the owner of an object’s monitor by
executing a method declared as synchronized
some methods may choose not to enforce mutual exclusion (unsynchronized)
by executing the body of a synchronized statement or block
synchronized construct specifies which object to acquire
supports finer-grained locking than “pure monitors” allow
exactly identical to the Modula-2 “LOCK(m) DO” construct in Birrell