Friday, October 06, 2006

Java MultiThreading - Monitor / Mutex ?

The central concept for synchronization in the Java model is the monitor. The central notion of a mutex concerns ownership. Only one thread can own the mutex at a time. If a second thread tries to "acquire" ownership, it will block (be suspended) until the owning thread "releases" the mutex.

The best analogy for a monitor is an airplane bathroom. Only one person can be in the bathroom at a time (we hope). Everybody else is queued up in a rather narrow aisle waiting to use it. As long as the door is locked, the bathroom is unaccessible. Given these terms, in our analogy the object is the airplane, the bathroom is the monitor (assuming there's only one bathroom), and the lock on the door is the mutex.

Author: Lakshmi S.V.S.M
Via: java-l@groups.ITtoolbox.com