Monitor Pattern

Monitor pattern is used to solve race condition problem in multi threaded environments. In Java it is implemented using synchronized keyword. An object can have any number of synchronized methods. For a thread to execute a synchronized method on an object, it needs to get a lock on that object. The thread holds the lock on the object as long as the method execution continues. While a thread holds a lock on an object, no other thread is given a lock on the same object and hence other threads cannot execute any of the synchronized
methods on the same object. Notice that a synchronized method is many times slower than normal methods.

Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License