mirror of
https://github.com/tiennm99/java-design-patterns.git
synced 2026-10-13 16:14:58 +00:00
improvement: Optimized NioReactor stop() (Reactor Pattern) (#1930)
* Optimized NioReactor stop() * Optimized ThreadPoolDispatcher stop()
This commit is contained in:
1 parent
4dcc20b733
commit
69883196d2
2 files changed
+7
-3
No files matched your search
@@ -96,9 +96,11 @@ public class NioReactor {
|
|||||||
* @throws IOException if any I/O error occurs.
|
* @throws IOException if any I/O error occurs.
|
||||||
*/
|
*/
|
||||||
public void stop() throws InterruptedException, IOException {
|
public void stop() throws InterruptedException, IOException {
|
||||||
reactorMain.shutdownNow();
|
reactorMain.shutdown();
|
||||||
selector.wakeup();
|
selector.wakeup();
|
||||||
reactorMain.awaitTermination(4, TimeUnit.SECONDS);
|
if (!reactorMain.awaitTermination(4, TimeUnit.SECONDS)) {
|
||||||
|
reactorMain.shutdownNow();
|
||||||
|
}
|
||||||
selector.close();
|
selector.close();
|
||||||
LOGGER.info("Reactor stopped");
|
LOGGER.info("Reactor stopped");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -64,6 +64,8 @@ public class ThreadPoolDispatcher implements Dispatcher {
|
|||||||
@Override
|
@Override
|
||||||
public void stop() throws InterruptedException {
|
public void stop() throws InterruptedException {
|
||||||
executorService.shutdown();
|
executorService.shutdown();
|
||||||
executorService.awaitTermination(4, TimeUnit.SECONDS);
|
if (executorService.awaitTermination(4, TimeUnit.SECONDS)) {
|
||||||
|
executorService.shutdownNow();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user