Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Can classes and/or objects be synchronized?  RSS feed

 
Ashish Agrawal
Ranch Hand
Posts: 112
  • Mark post as helpful
  • send pies
  • 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.
 
Joe Ess
Bartender
Posts: 9406
12
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • 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.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!