- NEVER DO THIS {@code @Override}public void messageReceived( {@link ChannelHandlerContext} ctx, ShutdownMessage msg) {{@link ChannelGroup} allChannels = MyServer.getAllChannels();{@link ChannelGroupFuture} future = allChannels.close();future.awaitUninterruptibly(); // Perform post-shutdown operation // ... } // GOOD {@code @Override}public void messageReceived(ChannelHandlerContext ctx, ShutdownMessage msg) { {@link ChannelGroup} allChannels = MyServer.getAllChannels();{@link ChannelGroupFuture} future = allChannels.close();future.addListener(new {@link ChannelGroupFutureListener}() { public void operationComplete( {@link ChannelGroupFuture} future) {// Perform post-closure operation // ... } }); }
In spite of the disadvantages mentioned above, there are certainly the cases where it is more convenient to call {@link #await()}. In such a case, please make sure you do not call {@link #await()} in an I/O thread. Otherwise,{@link IllegalStateException} will be raised to prevent a dead lock.