• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Can classes and/or objects be synchronized?

 
Ranch Hand
Posts: 112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello Ranchies,
Can classes and/or objects be synchronized? If yes, how?
As much as i know we can only synchronize method (instance methods and static methods). Is there any facility to synchronize classes/objects in jdk1.5's proposal? Same applies for variables.
Regards,
Ashish Agrawal.
 
Bartender
Posts: 9626
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Ashish Agrawal:

As much as i know we can only synchronize method (instance methods and static methods).


I think you are looking for a synchronized block:

If you synchronize a number of critical sections on the "this" handle, it has the effect of locking all those critical sections on the one particular instance of SomeClass (this would look more impressive if we had more than one critical section, of course). You can do the same for member variables of a class where critical sections depend on them.
Furthermore, synchronizing a static method has the effect of locking the corresponding Class object, so I think all the functionality you desire is alreadly there.
 
reply
    Bookmark Topic Watch Topic
  • New Topic