• 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:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Junilu Lacar
  • Liutauras Vilda
Sheriffs:
  • Paul Clapham
  • Jeanne Boyarsky
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
Bartenders:
  • Jesse Duncan
  • Frits Walraven
  • Mikalai Zaikin

Could Class be synchronized ?

 
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi,
Can class be synchronized ,if yes?
Then what is the need and why?

if ne body knew then please do favour by conveying.

regards
sachindra
 
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No..class cannot be Synchronized. We can have synchronized blocks or methods.
 
Ranch Hand
Posts: 154
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Your query is prone to ambiguous interpretation . What exactly do you mean by 'class synchronization'?

If you mean synchronizing on the class object of some class,then yes.

As for the need,well it could be for preventing race conditions arising out of multiple threads concurrently trying to access the static variables of a class.
 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
By saying 'if a class can be synchronized...' if you meant if a class member i.e., a static member can be synchronized then the answer is Yes. You just need to acquire lock on the Class object of the associated Java class.
Cheers,
Rohit
[ August 27, 2008: Message edited by: Bear Bibeault ]
 
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The question "can class be synchronized" does not make sense. A block of code can synchronize on the class.. for example: synchronize(MyClass.class) so that the code associated with all instances of that class cannot be re-entrant in that block. You can also synchronize on a single instance such as synchronize(this) or synchronize(xyz) where xyz is an instance. Make sense?
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic