Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

What does monitor mean?

 
d jones
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

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.

Thanks
 
Ulf Dittmer
Rancher
Pie
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Wikipedia is your friend: Monitor
 
Rancy Chadha
Ranch Hand
Posts: 135
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

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,
Rancy
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic