Synchronization, monitor, semaphore, synchronized keyword in Java

Multithreading leads to asynchronization in the programs. But, in some situations you need that the programs should perform synchronously. To introduce synchronization in the programs Java uses a process known as monitor also known as semaphore. Monitor is developed by C.A.R. Hoare. Monitor uses the concept of mutually exclusive lock (mutex). In this process a thread is held for execution and rest of the threads are kept on hold. Once the thread is in monitor it cannot be manipulated by other resources. This thread is locked in the monitor. The other threads wait for the monitor. Thus, synchronization is achieved. In Java every object has an associated monitor with it.

Synchronization can be achieved in Java by the use of synchronized keyword.


synchronized(object) {

here, object is reference to object that has to be synchronized.

Leave a Reply