Back to Intellij Community

MethodMayBeSynchronized

java/java-impl/resources/inspectionDescriptions/MethodMayBeSynchronized.html

2025.3-rc-2544 B
Original Source

Reports methods whose body contains a single synchronized statement. A lock expression for this synchronized statement must be equal to this for instance methods or [ClassName].class for static methods.

To improve readability of such methods, you can remove the synchronized wrapper and mark the method as synchronized.

Example:

public int generateInt(int x) {
    synchronized (this) {
      return 1;
    }
  }

After the quick-fix is applied:

public synchronized int generateInt(int x) {
    return 1;
  }