Think of a monitor like a lock. Every object has a monitor. A thread can lock this monitor for an object and while the thread is in a critical section (synchronized block), other threads cannot acquire this lock.
hello friend, java uses MONITORS to perform Sysncronization. Every object with Synchronized method is a monitor and the monitor lets only one thread at a time execute a synchronized method on the object.
Monitor is infact an Object that can block and allow a thread(s) to run. For this purpose Monitor provides every Object a lock and this lock is controlled by atmost one Thread at a particular time. And also putting synchronized keyword before a method decleration or a block just makes the lock of the object containing that code to be acquired by a single thread till that method(or synchronized block) is implemented by the thread that has got the lock.The thread gives up the lock after that.
Good heavens! What have you done! Here, try to fix it with this tiny ad:
Free, earth friendly heat - from the CodeRanch trailboss