synchronized modifier on methods.
There are several reasons a synchronized modifier on a method may be a bad idea:
synchronized block and
keep there only the code that works with shared state.
As an alternative, consider synchronizing on a private final lock object, access to which can be completely controlled.
A quick-fix is provided to wrap the method body with synchronized(this).
Example:
class Main {
public synchronized void fooBar() {
}
}
After the quick-fix is applied:
class Main {
public void fooBar() {
synchronized (this) {
}
}
}
You can configure the following options for this inspection:
synchronized method.