HashedWheelTimer is leaking threads, am I doing something wrong?
Virat Gohil
virat4lug at gmail.com
Tue Nov 3 11:14:25 EST 2009
On Tue, Nov 3, 2009 at 9:34 PM, Garry Watkins <garry at dynafocus.com> wrote:
>
> 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
Hi Garry,
Can you please post the code where you create a pipeline?
Thanks,
Virat
More information about the netty-users
mailing list