In
java, we are acquiring locks on the resources. Every Object treated
as a resource in java. Since Java is multi threaded, there is a
possibility for resource corruption, if multiple threads are working on the same resource. There should be a mechanism, to safely update
the resource. Here the monitor concept came to picture.
While performing any update on the resource, a thread must acquire a lock on
the resource. Then the thread which acquires lock on the resource,
update the resource, remaining all threads which want to work on this
resource must wait until it finishes. Once the the thread finishes
its updation with the resource, it asks the resource, to notify
remaining threads to update. Same procedure like acquiring lock,
releasing lock, notifying other threads repeats.
Since
in java every resource considers to be an object, so that wait,
notify and notifyAll kept in Object class.
Related Articles
Synchronization
Dead Lock
Dead Lock Example
Synchronized Method
static synchronized method
Synchronized block
Synchronization
Dead Lock
Dead Lock Example
Synchronized Method
static synchronized method
Synchronized block
No comments:
Post a Comment