0
我有一个Netty服务器,我需要在另一个线程中关闭请求Channel。这样做是否安全?如果没有,是否可以采取一些解决方法来解决它?任何建议表示赞赏!是Netty Channel.close()线程安全吗?
顺便说一句,我使用netty-4.0.34与NioEventLoopGroup。
AbstractChannelHandlerContext.java:514
@Override
public ChannelFuture close(final ChannelPromise promise) {
if (!validatePromise(promise, false)) {
// cancelled
return promise;
}
final AbstractChannelHandlerContext next = findContextOutbound();
EventExecutor executor = next.executor();
if (next.isHandlerAddedCalled() && executor.inEventLoop()) {
next.invokeClose(promise);
} else {
safeExecute(executor, new OneTimeTask() {
@Override
public void run() {
next.invokeClose(promise);
}
}, promise, null);
}
return promise;
}
如果被另一个线程的IO线程该通道一直坚持将最终没有关闭,因为“executor.inEventLoop()”将始终为false。这个解释是真的吗?
感谢Nicholas, – Walter
在我的场景中,我使用'org.quartz-scheduler'启动了一个计时器线程,并在时间do时关闭通道。由于计时器线程不是EventLoop中的IO线程,所以我想知道哪个线程最终会关闭进程? – Walter
您可能会考虑使用闲置处理程序来完成此操作。 – Nicholas