Lokvin Wiki
Register
Advertisement

ref doc

Singleton

static synchronized method

  1. difference between static synchronized method and non-static synchronized method
  • The lock objects are difference between static synchronized method and non-static synchronized method. Static synchronized method lock object is class object (lock object: FooClass.class), non-static synchronized lock object is instance object (lock object: this).
   public class Foo {
           public static synchronized void methodA() {}

           public synchronized void methodB() {}
   }

It's roughly equals

public class Foo {
  public static void methodA() {
    synchronized(Foo.class) {
        ...
    }
  }

  public void methodB() {
      synchronized(this){
      
      } 

  }
}

HashMap

Advertisement