File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Threads and Synchronization and the fly likes  methods and blocks can be synchronized Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Threads and Synchronization
Reply Bookmark " methods and blocks can be synchronized" Watch " methods and blocks can be synchronized" New topic
Author

methods and blocks can be synchronized

Saral Saxena
Ranch Hand

Joined: Apr 22, 2011
Posts: 200

Hi Folks ,
While going through and doing goggling on synchronization , I read that only methods and blocks can be synchronized and not variables and classes , please me what's the technical reason behind not keeping the variables and classes..!!
Praveen Kumar M K
Ranch Hand

Joined: Jul 03, 2011
Posts: 148
Although I haven't thought about this before, I'll venture a simple guess

Synchronization, as the word suggests, is a behaviourial mechanism and since methods and blocks form the behavior of a class, thats where synchronization has to be applied. Look at it from this perspective - variables form the current state of a class instance, and methods are the pieces of code which change this state(or behave differently). So it makes sense to only synchronize(a verb) methods/blocks.
 
 
subject: methods and blocks can be synchronized
 
Threads others viewed
No idea what is happening...
Blocks can be synchronized
Synchronized
synchronized methods and blocks worries
Could Class be synchronized ?
developer file tools