The only type of lock which is supported as a primitive in
Java is a re-entrant mutual exclusion lock.
The basic locking mechanism looks like this:
For any given object instance, only one
thread may be synchronized on it at a time. Before entering a synchronized block any thread memory caches will be flushed.
The following idioms can be expressed in terms of synchronized blocks:
For a more extensive selection of lock types, check out Doug Lea's
util.concurrent package (or wait until Java 1.5).