• Post Reply Bookmark Topic Watch Topic
  • New Topic

Class level syncronization v/s Method level Syncronization  RSS feed

 
Saurabh Agrawal
Ranch Hand
Posts: 244
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello everyone,

I have never found out the difference between class level syncronization and method level organization.

Can anyone elaborate on the same with some example?

I have been asked this question many a times in the interview but never got answer for myself.

Thanks in advance,
saurabh
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24215
37
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There's nothing called "method level synchonization" that contrasts with anything that could be called "class level sychronizations". One thing you might possibly be referring to is the difference between synchronization of class (static) methods and instance (non-static) methods. Instance methods are synchronized at the instance level -- i.e., threads compete for individual objects, but the same method can be called simultaneously on two separate objects. Static methods are synchronized on the Class object for the class, and all Threads must compete for that to call any static synchronized methods in a class.

I'm going to move this to our Threads and Synchronization forum; it surely isn't Advanced Java.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!