HashedWheelTimer is leaking threads, am I doing something wrong?
Garry Watkins
garry at dynafocus.com
Tue Nov 3 11:04:37 EST 2009
I have a reconnect handler that handles closed channels and it will try to
connect up after 10 seconds. Every time that it opens the connection back
up it creates a new thread. I am not sure if it is the wheel timer is
causing the leak or if there is something else. I am willing to try and
debug this if I can get a pointer in the right direction.
Here is what my code looks like:
@ChannelPipelineCoverage("one")
public class PLCDisconnectHandler extends SimpleChannelUpstreamHandler
{
private static final Log LOG =
LogFactory.getLog(PLCDisconnectHandler.class);
final ClientBootstrap bootstrap;
private final Timer timer;
public PLCDisconnectHandler(ClientBootstrap bootstrap, Timer timer) {
this.bootstrap = bootstrap;
this.timer = timer;
}
@Override
public void channelOpen(ChannelHandlerContext ctx, ChannelStateEvent e)
throws Exception
{
LOG.error("channelOpen");
super.channelOpen(ctx, e);
}
@Override
public void channelConnected(ChannelHandlerContext ctx,
ChannelStateEvent e) throws Exception {
LOG.error("channelConnected: " +
ctx.getChannel().getRemoteAddress().toString());
super.channelConnected(ctx, e);
}
@Override
public void channelDisconnected(ChannelHandlerContext ctx,
ChannelStateEvent e) throws Exception
{
LOG.error("Channel disconnected: " +
ctx.getChannel().getRemoteAddress().toString());
super.channelDisconnected(ctx, e);
}
@Override
public void channelClosed(ChannelHandlerContext ctx, ChannelStateEvent
e) {
LOG.error("channelClosed");
timer.newTimeout(new TimerTask() {
public void run(Timeout timeout) throws Exception {
timeout.cancel();
bootstrap.connect();
}
}, 10, TimeUnit.SECONDS);
}
@Override
public void exceptionCaught(ChannelHandlerContext ctx, ExceptionEvent e)
throws Exception {
if (e.getCause() instanceof ConnectException){
ctx.getChannel().close();
}
}
}
TIA
Garry
--
View this message in context: http://n2.nabble.com/HashedWheelTimer-is-leaking-threads-am-I-doing-something-wrong-tp3939379p3939379.html
Sent from the Netty User Group mailing list archive at Nabble.com.
More information about the netty-users
mailing list