Jose:
1) Class-level: Single lock for all the object instances of the class.
==> If the method is declared static and synchronized, then the thread which wants to execute that method could acquire the class lock. Class level is provided by Java to synchronize the static methods and static variables.
Example:
class Test{
static i;
static synchronized method()
{
System.out.println( i );
}
If any thread wants to execute this method, then it has to acquire the class lock. i.e, lock of the class
Test.
2) Object-level: Tasks can call same method in different objects of the same class.
Java provides lock for every object. If we have a class say, TestLock and when you create instances of that class, then each instance has a lock.
If a method in a class is declared synchronized in its declaration, then each thread has to acquire the lock of the current object.
If a part of the method in a class is preceded by synchronized( ObjectName), then that thread has to acquire the lock of that object.
If a part of the method in a class is preceded by synchronized( this), then that thread has to acquire the lock of current object.
Hope this helps...
Some one please do provide info about method-level...i did not hear about that so far...which is the good material to refer?