X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=policy-agent%2Fsrc%2Fmain%2Fjava%2Forg%2Foransc%2Fpolicyagent%2Frepository%2FLock.java;h=ed944924ca037963eea8127962584e4c3150cac0;hb=7de2f355ed1956001d15cb7e57fdd37fdf88cdc5;hp=ff3f331049239fdd5cacc5b2023c18904c49b939;hpb=cda38f944b12cd0ea8865a6f427a800f28991982;p=nonrtric.git diff --git a/policy-agent/src/main/java/org/oransc/policyagent/repository/Lock.java b/policy-agent/src/main/java/org/oransc/policyagent/repository/Lock.java index ff3f3310..ed944924 100644 --- a/policy-agent/src/main/java/org/oransc/policyagent/repository/Lock.java +++ b/policy-agent/src/main/java/org/oransc/policyagent/repository/Lock.java @@ -59,11 +59,16 @@ public class Lock { @Override public void run() { - while (true) { - for (LockRequest request : consume()) { - request.callback.success(request.lock); + try { + while (true) { + for (LockRequest request : consume()) { + request.callback.success(request.lock); + } + waitForNewEntries(); } - waitForNewEntries(); + } catch (InterruptedException e) { + Thread.currentThread().interrupt(); + logger.error("Interrupted {}", e.getMessage()); } } @@ -74,14 +79,9 @@ public class Lock { } @SuppressWarnings("java:S2274") - private synchronized void waitForNewEntries() { - try { - if (this.lockRequestQueue.isEmpty()) { - this.wait(); - } - } catch (InterruptedException e) { - logger.warn("waitForUnlock interrupted", e); - Thread.currentThread().interrupt(); + private synchronized void waitForNewEntries() throws InterruptedException { + if (this.lockRequestQueue.isEmpty()) { + this.wait(); } } } @@ -117,7 +117,7 @@ public class Lock { synchronized (this) { if (lockCounter <= 0) { lockCounter = -1; // Might as well stop, to make it easier to find the problem - throw new NullPointerException("Number of unlocks must match the number of locks"); + logger.error("Number of unlocks must match the number of locks"); } this.lockCounter--; if (lockCounter == 0) { @@ -130,7 +130,8 @@ public class Lock { @Override public String toString() { - return "Lock cnt: " + this.lockCounter + " exclusive: " + this.isExclusive; + return "Lock cnt: " + this.lockCounter + " exclusive: " + this.isExclusive + " queued: " + + this.lockRequestQueue.size(); } /** returns the current number of granted locks */ @@ -168,7 +169,7 @@ public class Lock { lockRequestQueue.add(new LockRequest(callback, lockType, this)); } - @SuppressWarnings("java:S2274") + @SuppressWarnings("java:S2274") // Always invoke wait() and await() methods inside a loop private synchronized void waitForUnlock() { try { this.wait();