File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes What does monitor mean? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "What does monitor mean?" Watch "What does monitor mean?" New topic

What does monitor mean?

d jones
Ranch Hand

Joined: Mar 13, 2006
Posts: 76

I came across the following statement "To call notify a thread must own the monitor lock."

What exactly does "monitor" mean? I have seen it used in a few articles but I'm not sure what it means.

Ulf Dittmer

Joined: Mar 22, 2005
Posts: 42965
Wikipedia is your friend: Monitor
Rancy Chadha
Ranch Hand

Joined: Jul 12, 2006
Posts: 135

The word "monitor" in Java refers to obtaining LOCK on an object.
If you know a little about threads in java. This concept of monitor is related to threads.
Every object has its own lock or you can say every object has its own monitor.
This lock comes into a major use when we use synchronized methods/block.
Once a thread enters a synchronized method/block it automatically gets a lock on the current
object or instance of class. And how does this help?
Obtaining lock will ensure that no other thread will be able to use that object until this thread
releases the lock. So any modification done to the state of Object can be done only by the current
thread who has the lock and no other thread can simultaneously make changes to the state of the object.
I hope this clears it.

But you will understand it better after you read SYNCRONIZED CODE section of K&B book.


Thanks,<br />-Rancy
I agree. Here's the link:
subject: What does monitor mean?
It's not a secret anymore!