Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4008760

RFE: compiler check for redundant locking

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Duplicate
    • Icon: P5 P5
    • None
    • 1.1
    • tools
    • None
    • sparc
    • solaris_2.5

      The compiler could check for me if I'm already inside a synchronized method or block and am trying to enter a synchronized block that locks the same lock as the outer lock (e.g. this). Yes, I know the spec says you can grab a lock more than once. The point is there's almost always a mistake when someone writes:

      public class SyncSync {
      public synchronized void method() {
      System.out.println("before");
      synchronized (this) {
      System.out.println("inside");
      }
      System.out.println("after");
      }

      because the before and after code is really inside the locked region, or they don't need the inner synchronized block.

      ... peter 10/11/96

            dstoutamsunw David Stoutamire (Inactive)
            pbk Peter Kessler
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: