Skip to content

Commit

Permalink
rename lock name
Browse files Browse the repository at this point in the history
Signed-off-by: neo <1100909+neowu@users.noreply.github.com>
  • Loading branch information
neowu committed Mar 22, 2024
1 parent aa8d2d0 commit fc9e605
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class MessageListenerThread extends Thread {
private final int concurrency;

private final ReentrantLock lock = new ReentrantLock();
private final Condition processingCondition = lock.newCondition();
private final Condition notProcessing = lock.newCondition();
private boolean processing;

private volatile boolean shutdown;
Expand All @@ -72,14 +72,14 @@ public void run() {
process();
} finally {
processing = false;
notifyProcessingCondition();
signal();
}
}

private void notifyProcessingCondition() {
private void signal() {
lock.lock();
try {
processingCondition.signalAll();
notProcessing.signalAll();
} finally {
lock.unlock();
}
Expand Down Expand Up @@ -139,7 +139,7 @@ boolean awaitTermination(long timeoutInMs) throws InterruptedException {
if (left <= 0) {
return false;
}
processingCondition.await(left, TimeUnit.MILLISECONDS);
notProcessing.await(left, TimeUnit.MILLISECONDS);
}
return true;
} finally {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public class ShutdownHandler implements ExchangeCompletionListener {
private final Logger logger = LoggerFactory.getLogger(ShutdownHandler.class);

private final ReentrantLock lock = new ReentrantLock();
private final Condition activeRequestCondition = lock.newCondition();
private final Condition noMoreActiveRequest = lock.newCondition();

private volatile boolean shutdown;

Expand Down Expand Up @@ -55,7 +55,7 @@ boolean awaitTermination(long timeoutInMs) throws InterruptedException {
if (left <= 0) {
return false;
}
activeRequestCondition.await(left, TimeUnit.MILLISECONDS);
noMoreActiveRequest.await(left, TimeUnit.MILLISECONDS);
}
return true;
} finally {
Expand All @@ -68,17 +68,17 @@ public void exchangeEvent(HttpServerExchange exchange, NextListener next) {
try {
int count = activeRequests.decrease();
if (count <= 0 && shutdown) {
notifyActiveRequestCondition();
signal();
}
} finally {
next.proceed();
}
}

private void notifyActiveRequestCondition() {
private void signal() {
lock.lock();
try {
activeRequestCondition.signalAll();
noMoreActiveRequest.signalAll();
} finally {
lock.unlock();
}
Expand Down

0 comments on commit fc9e605

Please sign in to comment.