title: How can I use a separate task executor for blocking sub tasks in netty?
body: <p>Situation: Given the telnet client &amp; server example of the official repo (<a href="https://github.com/netty/netty/tree/4.0/example/src/main/java/io/netty/example/telnet" rel="nofollow">https://github.com/netty/netty/tree/4.0/example/src/main/java/io/netty/example/telnet</a>), I've change this a little bit using a fake blocking task: <a href="https://github.com/knalli/netty-with-bio-task/tree/master/src/main/java/de/knallisworld/poc" rel="nofollow">https://github.com/knalli/netty-with-bio-task/tree/master/src/main/java/de/knallisworld/poc</a></p>
  
  <p>This is Netty 4!</p>
  
  <p>Instead of echo replying the message (like the telnet server demo does), the channel handler blocks the thread for some time (in real world with things like JDBC or JSch, ...).</p>
  
  <pre><code>try { Thread.sleep(3000); } catch (InterruptedException e) {};
  future = ctx.write("Task finished at " + new Date());
  future.addListener(ChannelFutureListener.CLOSE);
  </code></pre>
  
  <p>This actually works: I'm testing this with a <code>echo "Hello" | nc localhost $port)</code> and the thread will be blocked (and <code>nc</code> waits) until it returns 3 seconds later.</p>
  
  <p>However, this means I'm blocking a thread of Netty's event loop worker group with an unrelated task.</p>
  
  <p>Therefor, I've changed the channel registration and applied a custom executor:</p>
  
  <pre><code>public class TelnetServerInitializer extends ChannelInitializer&lt;SocketChannel&gt; {
  
      private static final StringDecoder DECODER = new StringDecoder();
      private static final StringEncoder ENCODER = new StringEncoder();
  
      private TelnetServerHandler serverHandler;
      private EventExecutorGroup executorGroup;
  
      public TelnetServerInitializer() {
          executorGroup = new DefaultEventExecutorGroup(10);
          serverHandler = new TelnetServerHandler();
      }
  
      @Override
      protected void initChannel(final SocketChannel ch) throws Exception {
          ChannelPipeline pipeline = ch.pipeline();
  
          pipeline.addLast("framer", new DelimiterBasedFrameDecoder(
              8192, Delimiters.lineDelimiter()));
  
          pipeline.addLast("decoder", DECODER);
          pipeline.addLast("encoder", ENCODER);
  
          // THIS!
          pipeline.addLast(executorGroup, "handler", serverHandler);
      }
  }
  </code></pre>
  
  <p>Unfortunately, after this configuration the socket will be closed immediately after exiting handler's <code>channelRead0()</code>. I can see that the task itself will be processed including calling the handler's event methods. But the corresponding channel is already disconnected to the client (my <code>nc</code> command as already exited).</p>
  
  <p>How does integrating another executor work? Am I missing a detail?</p>