This week's book giveaway is in the Kotlin forum.
We're giving away four copies of Kotlin in Action and have Dmitry Jemerov & Svetlana Isakova on-line!
See this thread for details.
Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Monitor  RSS feed

 
V Srinivasan
Ranch Hand
Posts: 99
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Which is being considered as Monitor while discussing Thread subject. I am not getting a clear definition about it.
Thanks
 
Jim Baiter
Ranch Hand
Posts: 532
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
madhusr
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
monitor is something like a block for an object of thread which does not allow other threads to enter when synchronised
------------------
 
V Srinivasan
Ranch Hand
Posts: 99
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How come? Monitor is also an object.
 
Jim Baiter
Ranch Hand
Posts: 532
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can get the official definition by looking at the Java Language Specification, Chapter 17.
 
kiran babu
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
sandeep bagati
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!