Commits

Michael Ludwig  committed 9ccdcfc

Properly add lock when not present.

  • Participants
  • Parent commits 5ba3adc

Comments (0)

Files changed (1)

File src/main/java/com/lhkbob/entreri/task/Scheduler.java

             // this will either return the newly constructed lock, or 
             // the lock inserted from another thread after we tried to fetch it,
             // in either case, the lock is valid
-            lock = typeLocks.putIfAbsent(id, new ReentrantLock());
+            ReentrantLock newLock = new ReentrantLock();
+            lock = typeLocks.putIfAbsent(id, newLock);
+            if (lock == null) {
+                // newLock was the assigned one
+                lock = newLock;
+            }
         }
         return lock;
     }