is not a @Sharable handler解决方法

Posted muzhongjiang

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了is not a @Sharable handler解决方法相关的知识,希望对你有一定的参考价值。

is not a @Sharable handler解决方法

 

昨天在写编码器的时候,因为是和spring整合,因此在使用编码的时候用Autowired自动注入

@Autowired
private ProtocolDecoder protocolDecoder ;

@Autowired
private ProtocolEncoder protocolEncoder;

结果在多个客户端连接(其实不是多客户端的问题)的时候导致一直在报错,如下

io.netty.channel.ChannelPipelineException: com.mzj.ProtocolDecoder is not a @Sharable handler, so can‘t be added or removed multiple times.

于是我就自作聪明的将ProtocolDecoder上加了个@Sharable注解,结果在启动的时候就报错了。

Caused by: java.lang.IllegalStateException: ChannelHandler com.mzj.ProtocolDecoder is not allowed to be shared

最后的解决方法是,不要使用单例了,每次添加handler的时候直接new

        pipeline.addLast("decoder",new ProtocolDecoder() );
        pipeline.addLast("encoder",new ProtocolEncoder()) ;

当然如果是在ChannelInitializer的子类报错说is not a @Sharable handler,一般情况加上@Sharable注解即可

 

以上是关于is not a @Sharable handler解决方法的主要内容,如果未能解决你的问题,请参考以下文章

RMAN-06172: no AUTOBACKUP found or specified handle is not a valid copy or piece

swift 报错 Call can throw, but it is not marked with 'try' and the error is not handled

Swift:Errors thrown from here are not handled because the enclosing catch is not exhaustive

Swift:Errors thrown from here are not handled because the enclosing catch is not exhaustive

新vm打开以前的虚拟机报错"Could not get vmci driver version: The handle is invalid."

system service exception not handled蓝屏