improvement: Optimized NioReactor stop() (Reactor Pattern) (#1930)
* Optimized NioReactor stop() * Optimized ThreadPoolDispatcher stop()
This commit is contained in:
parent
4dcc20b733
commit
69883196d2
@ -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();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user