• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Tim Cooke
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Frank Carver
  • Henry Wong
  • Ron McLeod
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Himai Minh

Synchronised and notifyAll

 
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.

 
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks very much. I understand a lot better now.
 
On top of spaghetti all covered in cheese, there was this tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic