Yes, if the method is not static
.
A synchronized
non-static method is synchronized on this
. So this method:
public synchronized void foo() {
}
actually equivalent to this:
public void foo() {
synchronized(this) {
}
}
Synchronized methodA is static
synchronized with the current class. So this method:
public static synchronized void bar() {
}
actually equivalent to this:
public static void bar() {
synchronized(ThisClass.class) {
}
}
source
share