Java class level lock vs. object level lock

No, it doesn’t mean that. The “class level lock” is just a regular lock on a different object, namely SomeClass.class. The “object level lock” locks on this.

Edit: Just to make sure I’m following your understanding of the terminology, you’re wondering if m1 and m2 can be run concurrently as they are defined below:

public class SomeClass {
    public synchronized static void m1() {
       //do something
    }

    public synchronized void m2() {
       //do something
    }
}

And the answer is yes, m1 and m2 can be run concurrently. It is functionally equivalent to this:

public class SomeClass {
    public static void m1() {
        synchronized (SomeClass.class) {
           //do something
        }
    }
    public void m2() {
        synchronized (this) {
           //do something
        }
    }
}

Since they are synchronizing on completely different objects, they are not mutually exclusive.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)