Skip to content

Commit 98a66e8

Browse files
author
Peter Svensson
committed
expose the shutdown method of the event loop group
To exit normally all non-daemon threads of the java process are supposed to have stopped. TcpClientSession creates an static class member EventLoopGroup which in turn instantiates worker threads. These need to be stopped as a part of shutting down the server. This patch exposes the shutdown of the EventLoopGroup as a static function intended to be called by some central function as a part of server shutdwon. Nullify the EventLoopGroup in preparation for starting new users of TcpClientSession.
1 parent bfb6430 commit 98a66e8

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

src/main/java/com/github/steveice10/packetlib/tcp/TcpClientSession.java

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,20 @@ private static void createTcpEventLoopGroup() {
316316
break;
317317
}
318318

319-
Runtime.getRuntime().addShutdownHook(new Thread(() -> EVENT_LOOP_GROUP.shutdownGracefully()));
319+
Runtime.getRuntime().addShutdownHook(new Thread(() -> shutdownEventLoopGroup()));
320+
}
321+
322+
public static void shutdownEventLoopGroup() {
323+
if (EVENT_LOOP_GROUP != null) {
324+
try {
325+
EVENT_LOOP_GROUP.shutdownGracefully().sync();
326+
EVENT_LOOP_GROUP = null;
327+
CHANNEL_CLASS = null;
328+
DATAGRAM_CHANNEL_CLASS = null;
329+
} catch (InterruptedException e) {
330+
e.printStackTrace();
331+
}
332+
333+
}
320334
}
321335
}

0 commit comments

Comments
 (0)