• Post Reply Bookmark Topic Watch Topic
  • New Topic

methods and blocks can be synchronized

 
Saral Saxena
Ranch Hand
Posts: 203
Eclipse IDE Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 256
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!