Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/360.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Netty ServerSocket和子系统关闭_Java_Server_Netty_Application Shutdown - Fatal编程技术网

Java Netty ServerSocket和子系统关闭

Java Netty ServerSocket和子系统关闭,java,server,netty,application-shutdown,Java,Server,Netty,Application Shutdown,我想关闭Netty服务器上的服务器套接字,然后等待所有子服务器完成处理,然后再执行资源清理 步骤1 使用此代码等待Netty服务器套接字在主线程上关闭,b是ServerBootstrap b.bind ( getPort ( p ) ).sync ().channel ().closeFuture ().sync () 步骤2 指示服务器套接字从应用程序中其他位置的不同线程关闭 步骤3 指示所有客户端关闭,我将有应用程序代码来执行此操作 步骤4 等待所有客户端套接字关闭,这就是我想知道的方法。

我想关闭Netty服务器上的服务器套接字,然后等待所有子服务器完成处理,然后再执行资源清理

步骤1 使用此代码等待Netty服务器套接字在主线程上关闭,
b
ServerBootstrap

b.bind ( getPort ( p ) ).sync ().channel ().closeFuture ().sync ()
步骤2 指示服务器套接字从应用程序中其他位置的不同线程关闭

步骤3 指示所有客户端关闭,我将有应用程序代码来执行此操作

步骤4 等待所有客户端套接字关闭,这就是我想知道的方法。如何获取所有客户端套接字、服务器子级的列表,然后等待它们全部关闭

网络版4.1.1.最终版

我使用以下代码片段设置Netty服务器套接字

EventLoopGroup bossGroup = new NioEventLoopGroup ( 1 );
EventLoopGroup workerGroup = new NioEventLoopGroup ( Math.max ( 1, Runtime.getRuntime ().availableProcessors () / 2 ) );
try
{
  ServerBootstrap b = new ServerBootstrap ();
  b.group ( bossGroup, workerGroup )
  .channel ( NioServerSocketChannel.class )
  .childHandler ( new ServerInitializer ( sslctx, jsonIOManager, dispatcherPool, factory ) )
  .childOption ( ChannelOption.TCP_NODELAY, Boolean.TRUE )
  .childOption ( ChannelOption.SO_KEEPALIVE, Boolean.TRUE );

  // wait till server socket is closed    
  b.bind ( getPort ( p ) ).sync ().channel ().closeFuture ().sync ();
  // instruct all clients to shutdown
  dispatcherPool.shutdown ();

  // wait on all sockets that are children of the server socket to close
  // How can i do this?

}
finally
{
  bossGroup.shutdownGracefully ();
  workerGroup.shutdownGracefully ();
}
从中可以看出,只要等待
正常关闭
返回,就会等待所有套接字关闭

关闭Netty应用程序通常与关闭应用程序一样简单 关闭通过shutdownGracefully()创建的所有EventLoopGroup。信息技术 返回一个Future,当EventLoopGroup已启动时通知您 完全终止,属于该组的所有通道都已终止 已经关闭了