This week's book giveaway is in the Mac OS forum. We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line! See this thread for details.
The "monitor" is any object. When you say "handle it directly", what kind of "handling" did you have in mind? Normally all you do is to call methods like wait() and notify() on the monitor. There isn't anything more direct than that.
Joined: Mar 04, 2008
Paul Clapham wrote:The "monitor" is any object. When you say "handle it directly", what kind of "handling" did you have in mind? Normally all you do is to call methods like wait() and notify() on the monitor. There isn't anything more direct than that.
Java's monitor supports two kinds of thread synchronization: mutual exclusion and cooperation. Mutual exclusion, which is supported in the Java virtual machine via object locks, enables multiple threads to independently work on shared data without interfering with each other. Cooperation, which is supported in the Java virtual machine via the wait and notify methods of class Object, enables threads to work together towards a common goal.
Really, Todd, if you have a question about what Bill Venners wrote, you should ask him that question.
But it's helpful that we now have a background for your question. That might make it easier to answer. But the other thing we need is background on you. I get the impression that you're a beginner in the threading area. If that's the case then you are better off not reading detailed technical descriptions of how the JVM takes care of synchronization under the covers. You aren't going to understand the concepts if you don't have any basic framework to put those concepts into.
Joined: Mar 04, 2008
Actually I'm not new in Java, even multiple threading. I started using Java since 1.0 release.
I was interviewed recently and asked a question: What is Java monitor?
I think I know what the monitor does, but could not come up with a nice clean answer.
I see. But I wouldn't consider a four-page web article a "nice clean answer" either. Way too much detail. On the other hand "It's any object" probably isn't enough detail for an answer to an interview question. But really it's true. Any object can be a monitor for Java synchronization, so if you're just asked plain old "What is a monitor" then -- answering the question with an answer of the same level of detail -- you could say "It's any Java object". The follow-on questions might go into more detail.