Yes, if the method is not static.
A synchronizednon-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 staticsynchronized 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