This week's book giveaway is in the General Computing forum.
We're giving away four copies of Arduino in Action and have Martin Evans, Joshua Noble, and Jordan Hochenbaum on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Synchronised and notifyAll Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Reply Bookmark "Synchronised and notifyAll" Watch "Synchronised and notifyAll" New topic
Author

Synchronised and notifyAll

Eleanor Leong
Greenhorn

Joined: Mar 24, 2006
Posts: 21
The following code is inside a method. What does TThread94.class means
in the code. Is it an Object or a Class?
I think it is trying to synchronized against the TThread94 Class and
using it to notifyAll()?
It is a compile error if I just used TThread.notifyAll(), complaining
non-static method notifyAll() cannot be referenced from a static context.

Chandramouli Ram
Ranch Hand

Joined: Mar 07, 2005
Posts: 65
Hi Eleanor,

You guessed it right. I believe that the class TThread94 has some static method that's synchronized, and there are competing threads to access it. So to notify those threads, the Class "object" of TThread94 must be used, as notifiyAll() is an instance (and not static) method of class Object. That's the reason you got a compilation error when you try to invoke TThread94.notifyAll().
TThread94.class returns the class object that is created when the class TThread94 is loaded.

As Java has both class Class and class Object and because class and object are also the most frequently used terms in the language, it's kind of difficult to explain a scenario such as this with unambiguous language

Hope this helps!


Thanks & Regards,<br />Chandramouli Ram
Eleanor Leong
Greenhorn

Joined: Mar 24, 2006
Posts: 21
Thanks very much. I understand a lot better now.
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: Synchronised and notifyAll
 
Similar Threads
two questiones about synchronized block.
Threads - Notify question
Database Connection Pool Not Releasing Connection to pool
Am I right about wait() and notifyAll()
Threads