Right way to shutdown in case of error
float_dublin
Kostya.Hvan at gmail.com
Sun Sep 13 15:01:24 EDT 2009
Hello,
If i try to shutdown netty in exceptionCaught method it hangs forever,
searching this mail list shows i should do it in separate thread, is it the
only right way to close and release resources?
Code snippet to reproduce Connection Refused hang:
public class ClientTest {
@ChannelPipelineCoverage("all")
private class Client extends SimpleChannelHandler {
@Override
public void exceptionCaught(ChannelHandlerContext ctx, final
ExceptionEvent e) throws Exception {
e.getCause().printStackTrace();
// new Thread() {
//
// @Override
// public void run() {
e.getChannel().close().awaitUninterruptibly();
cb.releaseExternalResources();
// }
// }.start();
}
}
ClientBootstrap cb = new ClientBootstrap(new
NioClientSocketChannelFactory(
Executors.newCachedThreadPool(),
Executors.newCachedThreadPool()));
private void initClient() {
cb.setOption("tcpNoDelay", true);
cb.setOption("keepAlive", true);
final ChannelPipeline pipeline = cb.getPipeline();
pipeline.addLast("handler", new Client());
cb.connect(new InetSocketAddress("localhost", 20001)); // Assuming
nobody is home
}
public static void main(String[] args) {
new ClientTest().initClient();
}
}
--
View this message in context: http://n2.nabble.com/Right-way-to-shutdown-in-case-of-error-tp3637599p3637599.html
Sent from the Netty User Group mailing list archive at Nabble.com.
More information about the netty-users
mailing list