I assume that you mean synchronization lock. If you are not familiar with synchronization, this means that the same code is simultaneously launched by two different threads. In java synchronization, it is performed using object locks:
Object lock = new Object(); public void doSomething(){ ... synchronized(lock){
This code ensures that only one thread can do something dangerous at a given time, and it will complete everything in a synchronized block before another thread can run the same code. I assume that you call "class level locking" - this is an implicit locking by a synchronized method:
public synchronized void somethingDangerous(){...}
Here again, only one thread can execute the method at any given time and will always be finished before another thread can start executing the code. This is equivalent to a synchronized block on "this":
public void somethingDangerous(){ synchronized(this){
Now this lock is not actually on the class, but on one instance (i.e. not on all watches, but only on your watch). If you need a true “class level lock” (usually done by the static method), you need to synchronize something regardless of any instances. For instance:
public class Clock{ private static Object CLASS_LOCK = new Object(); public static void doSomething(){ ... synchronized(CLASS_LOCK){
again there is an implicit lock for static methods:
public class Clock{ public static synchronized void somethingDangerous(){} }
which is the equivalent of locking an object of a class:
public class Clock{ public static void somethingDangerous(){ synchronized(Clock.class){
source share