Hi,
first of all: I'm still very unfamiliar with Netty, and I'm sorry if I really missed the correct solution. I've looked into the repo's examples, but it seems there no such one?
My goal: trying to integrate an unavoidable blocking task (let's say a JSch or JDBC connection pool) into a Netty nio flow.
As far as I know yet, a blocking task is basically no problem (it will work). However, it blocks at least one worker being part of the event loop worker group.
ChannelFuture future = new BlockingCall(ctx).call();
future.addListener(ChannelFutureListener.CLOSE);
using
BlockingCall as a simple Callable with a Thread.sleep (shortend)
class BlockingCall implements Callable<ChannelFuture> {
private final ChannelHandlerContext ctx;
public BlockingCall(ChannelHandlerContext ctx) {
this.ctx = ctx;
}
@Override
public ChannelFuture call() throws Exception {
try { Thread.sleep(3000); } catch (InterruptedException e) {
return ctx.write("Task finished at " + new Date());
}
}
With that configuration, the channel works fine. A simple echo "123" | nc $localhost $port will wait 3 seconds to reply.
// constructor
executorGroup = new DefaultEventExecutorGroup(10);
// initChannel
pipeline.addLast(executorGroup, "handler", serverHandler);
the channel will be closed right after leaving channelRead0. I can see with debugging/logging that the task will be processed correctly incl. receiving events in the handler.. but the channel is already closed (my echo/nc command from above returns immediately).
Am I running into a bug, or did i misunderstood how move a blocking task out of netty worker pool?
Thank you very much!