Home > Back-end >  Use netty channelFuture. Channel (.) closeFuture (). The sync (); Blocking the main thread is regist
Use netty channelFuture. Channel (.) closeFuture (). The sync (); Blocking the main thread is regist

Time:10-09

 
Public void the start () {
//create two thread group
NioEventLoopGroup boss=new NioEventLoopGroup ();
NioEventLoopGroup work=new NioEventLoopGroup ();
Try {
ServerBootstrap bootstrap=new ServerBootstrap ();
The bootstrap. Channel (NioServerSocketChannel. Class);
The bootstrap. Handler (new LoggingHandler (LogLevel. DEBUG));
The bootstrap. Group (boss, work);
The bootstrap. ChildHandler (new NettyChannelInitializer (cloudWsiController, prefix, nettyUtils));

ChannelFuture ChannelFuture=the bootstrap. Bind (port). The sync ();
Logger. The info (" netty server start... ");
ChannelFuture. Channel (.) closeFuture (). The sync ();

{} catch InterruptedException (e)
E.p rintStackTrace ();
Logger. Warn (" operation error, close the connection: "+ um participant etMessage ());
//boss. ShutdownGracefully ();
//work. ShutdownGracefully ();

} the finally {
Boss. ShutdownGracefully ();
Work. ShutdownGracefully ();
Logger. The info (" websocket server has shut down ");
}
}


Unable to register to euaeka

 
Public void the start () {
//create two thread group
NioEventLoopGroup boss=new NioEventLoopGroup ();
NioEventLoopGroup work=new NioEventLoopGroup ();
Try {
ServerBootstrap bootstrap=new ServerBootstrap ();
The bootstrap. Channel (NioServerSocketChannel. Class);
The bootstrap. Handler (new LoggingHandler (LogLevel. DEBUG));
The bootstrap. Group (boss, work);
The bootstrap. ChildHandler (new NettyChannelInitializer (cloudWsiController, prefix, nettyUtils));

ChannelFuture ChannelFuture=the bootstrap. Bind (port). The sync ();
Logger. The info (" netty server start... ");
//channelFuture. Channel (.) closeFuture (). The sync ();

{} catch InterruptedException (e)
e.printStackTrace();
Logger. Warn (" operation error, close the connection: "+ um participant etMessage ());
Boss. ShutdownGracefully ();
Work. ShutdownGracefully ();

} the finally {
//boss. ShutdownGracefully ();
//work. ShutdownGracefully ();
//logger. The info (" websocket server has shut down ");
}
}


After such changes often appear Java. Nio. Abnormal channels. ClosedChannelException (An exceptionCaught () event was fired, and it reached the at the tail of the pipeline. It usually means the last handler in the pipeline did not handle the exception)

Do you have any better solution?

  • Related