@@ -26,6 +26,7 @@ public class NettyHttpServer implements Runnable, Closeable {
2626 private final int port ;
2727 private final int connectionBacklog = 128 ;
2828
29+ private final EventLoopGroup bossGroup ;
2930 private final EventLoopGroup processorGroup ;
3031 private final ThreadPoolExecutor executorGroup ;
3132 private final HttpResponseStatus responseStatus ;
@@ -37,8 +38,14 @@ public NettyHttpServer(String host, int port, IMessageHandler messageHandler,
3738 this .host = host ;
3839 this .port = port ;
3940 this .responseStatus = HttpResponseStatus .valueOf (responseCode );
41+
42+ // boss group is responsible for accepting incoming connections and sending to worker loop
43+ // process group is channel handler, see the https://github.com/netty/netty/discussions/13305
44+ // see the https://github.com/netty/netty/discussions/11808#discussioncomment-1610918 for why separation is good
45+ bossGroup = new NioEventLoopGroup (1 , daemonThreadFactory ("http-input-connector" ));
4046 processorGroup = new NioEventLoopGroup (threads , daemonThreadFactory ("http-input-processor" ));
4147
48+ // event handler group
4249 executorGroup = new ThreadPoolExecutor (threads , threads , 0 , TimeUnit .MILLISECONDS ,
4350 new ArrayBlockingQueue <>(maxPendingRequests ), daemonThreadFactory ("http-input-handler-executor" ),
4451 new CustomRejectedExecutionHandler ());
@@ -51,7 +58,7 @@ public NettyHttpServer(String host, int port, IMessageHandler messageHandler,
5158 }
5259
5360 serverBootstrap = new ServerBootstrap ()
54- .group (processorGroup )
61+ .group (bossGroup , processorGroup )
5562 .channel (NioServerSocketChannel .class )
5663 .option (ChannelOption .SO_BACKLOG , connectionBacklog )
5764 .childOption (ChannelOption .SO_KEEPALIVE , true )
@@ -73,7 +80,9 @@ public void run() {
7380 public void close () {
7481 try {
7582 // stop accepting new connections first
76- processorGroup .shutdownGracefully (0 , 10 , TimeUnit .SECONDS ).sync ();
83+ bossGroup .shutdownGracefully ().sync ();
84+ // stop the worker group
85+ processorGroup .shutdownGracefully ().sync ();
7786 // then shutdown the message handler executor
7887 executorGroup .shutdown ();
7988 try {
0 commit comments