this
or class
expressions.
The reported constructs include synchronized
blocks and calls to wait()
,
notify()
or notifyAll()
.
There are several reasons synchronization on this
or class
expressions may be a bad idea:
As an alternative, consider synchronizing on a private final
lock object, access to which can be completely controlled.
Example:
public void print() {
synchronized(this) { // warning: Lock operations on 'this' may have unforeseen side-effects
System.out.println("synchronized");
}
}