When a Java member needs to be thread safe, we need to do the following:
public synchronized void func() { ... }
This syntax is equivalent to:
public void func() { synchronized(this) { .... } }
That is, it actually uses this to block.
My question is: if I use synchronized using the static method as follows:
class AA { private AA() {} public static synchronized AA getInstance() { static AA obj = new AA(); return obj; } }
In this case, what is the lock for the synchronized method?
source share