• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Synchronised and notifyAll

 
Eleanor Leong
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 65
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!
 
Eleanor Leong
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks very much. I understand a lot better now.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic