aspose file tools
The moose likes Threads and Synchronization and the fly likes Can a class be synchronized Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Threads and Synchronization
Reply Bookmark "Can a class be synchronized" Watch "Can a class be synchronized" New topic
Author

Can a class be synchronized

ravisha andar
Ranch Hand

Joined: Feb 25, 2011
Posts: 55
Hi All,


Can anybody please let me know why a class cant be synchronized ?

Regards,
Ravisha
Martin Vajsar
Bartender

Joined: Aug 22, 2010
Posts: 1219

Well, the first problem I can see is that it is not clear how a synchronized class should behave. It is not defined anywhere. If you try to come up with a definition of your own, you might soon get into some trouble (what about static methods, public fields, public static fields etc.)

Secondly, it might not benefit you much. The most naive interpretation of a "synchronized class" is rather easily doable in Java: just make every non-private method synchronized and every non-final field private. In my experience you usually want more sophisticated design, therefore the real use of this "synchronized class" would be very limited anyway.
 
 
subject: Can a class be synchronized
 
Threads others viewed
thread safe
Thread-safe Action class ?
Can Overloaded method be synchronized
Threading
Could Class be synchronized ?
developer file tools