@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());
}
}
}
@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();
}
}
}
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) {
@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 */