Netty:我可以在管道和通道未来的监听器中提供静态空闲状态处理程序吗
Netty: Can I give static Idle state handler in pipeline and channel future listener
在通道初始化器中,
protected void initChannel(SocketChannel ch) throws Exception {
MessageHandler handler = new MessageHandler(channelGroup);
ch.pipeline().addLast(DECODER, new MessageDecoder())
.addLast(ENCODER, newMessageEncoder())
.addLast(idleExecutor, "idleHandler", new IdleStateHandler(0, 0, 6*60))
.addLast(pipelineExecutor, "handler", handler);
}
在上面的一段代码中,当通道初始化时,我可以使用 IdleStateHandler 的静态对象,而不是为每个通道使用一个新实例。它是线程安全的吗?
此外,
当我向频道写东西时。
我向它添加了一个空闲读取处理程序,这样如果我在某个时候没有收到响应,我就会关闭频道。
ChannelPipeline pipeline = channel.pipeline();
pipeline.addAfter(ChannelInitializer.idleExecutor,
"idleHandler", "idleReadHandler",new IdleStateHandler(60, 0, 0));
我可以在上面的代码中使用 static idleReadHandler 吗?
我正在使用 Netty-4.1.0
它在 jboss 文档中被标记为可共享,直到 netty 3.x
https://docs.jboss.org/netty/3.2/api/org/jboss/netty/handler/timeout/IdleStateHandler.html
但是在 4.x 文档中看不到
在netty中,决定一个handler是否可以在多通道间线程安全使用的规则是@Shareable注解。由于IdleStateHandler
没有注解注解,说明不能安全使用
在通道初始化器中,
protected void initChannel(SocketChannel ch) throws Exception {
MessageHandler handler = new MessageHandler(channelGroup);
ch.pipeline().addLast(DECODER, new MessageDecoder())
.addLast(ENCODER, newMessageEncoder())
.addLast(idleExecutor, "idleHandler", new IdleStateHandler(0, 0, 6*60))
.addLast(pipelineExecutor, "handler", handler);
}
在上面的一段代码中,当通道初始化时,我可以使用 IdleStateHandler 的静态对象,而不是为每个通道使用一个新实例。它是线程安全的吗?
此外,
当我向频道写东西时。 我向它添加了一个空闲读取处理程序,这样如果我在某个时候没有收到响应,我就会关闭频道。
ChannelPipeline pipeline = channel.pipeline();
pipeline.addAfter(ChannelInitializer.idleExecutor,
"idleHandler", "idleReadHandler",new IdleStateHandler(60, 0, 0));
我可以在上面的代码中使用 static idleReadHandler 吗?
我正在使用 Netty-4.1.0
它在 jboss 文档中被标记为可共享,直到 netty 3.x https://docs.jboss.org/netty/3.2/api/org/jboss/netty/handler/timeout/IdleStateHandler.html 但是在 4.x 文档中看不到
在netty中,决定一个handler是否可以在多通道间线程安全使用的规则是@Shareable注解。由于IdleStateHandler
没有注解注解,说明不能安全使用