You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by GitBox <gi...@apache.org> on 2021/07/02 04:13:40 UTC
[GitHub] [pulsar] 315157973 commented on pull request #11183: Fix the dead lock when using hasMessageAvailableAsync and readNextAsync
315157973 commented on pull request #11183:
URL: https://github.com/apache/pulsar/pull/11183#issuecomment-872699118
Great work! This is very difficult to troubleshoot, thanks penghui
When the Future has been completed, use future.whenComplete at this time, and the current thread will be used. A thread switch causes a deadlock. Here is a Demo:
```
CompletableFuture<Void> future = new CompletableFuture<>();
ScheduledExecutorService executorService = new ScheduledThreadPoolExecutor(1,
new BasicThreadFactory.Builder().namingPattern("metrics-schedule-pool-%d").build());
executorService.execute(() -> {
System.out.println("executorService:" + Thread.currentThread().getName());
future.complete(null);
});
Thread.sleep(5000);
future.whenComplete(((unused, throwable) -> {
System.out.println("whenComplete:" + Thread.currentThread().getName());
}));
System.out.println("out:" + Thread.currentThread().getName());
```

--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org