Skip to content

Commit

Permalink
improvement: Optimized NioReactor stop() (Reactor Pattern) (#1930)
Browse files Browse the repository at this point in the history
* Optimized NioReactor stop()

* Optimized ThreadPoolDispatcher stop()
  • Loading branch information
yuhangbin authored Dec 23, 2021
1 parent 4dcc20b commit 6988319
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,11 @@ public void start() {
* @throws IOException if any I/O error occurs.
*/
public void stop() throws InterruptedException, IOException {
reactorMain.shutdownNow();
reactorMain.shutdown();
selector.wakeup();
reactorMain.awaitTermination(4, TimeUnit.SECONDS);
if (!reactorMain.awaitTermination(4, TimeUnit.SECONDS)) {
reactorMain.shutdownNow();
}
selector.close();
LOGGER.info("Reactor stopped");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ public void onChannelReadEvent(AbstractNioChannel channel, Object readObject, Se
@Override
public void stop() throws InterruptedException {
executorService.shutdown();
executorService.awaitTermination(4, TimeUnit.SECONDS);
if (executorService.awaitTermination(4, TimeUnit.SECONDS)) {
executorService.shutdownNow();
}
}
}

0 comments on commit 6988319

Please sign in to comment.