3

messageReceivedこんにちは、予想時間内に呼び出されないイベントを受け取りたいです。私は、コンテキストを閉じずに何らかの作業を行って戻る場所でReadTimeoutHandler処理できる例外を生成する場所を試しました。exceptionCaught()しかし、その直後に私はたくさんの例外を得ました

Nov 18, 2012 8:56:34 AM io.netty.channel.ChannelInitializer
WARNING: Failed to initialize a channel. Closing: [id: 0xa81de260, /127.0.0.1:59763 => /127.0.0.1:59724]
io.netty.channel.ChannelHandlerLifeCycleException: io.netty.handler.timeout.ReadTimeoutHandler is not a @Sharable handler, so can't be added or removed multiple times.
    at io.netty.channel.DefaultChannelPipeline.callBeforeAdd(DefaultChannelPipeline.java:629)
    at io.netty.channel.DefaultChannelPipeline.addLast0(DefaultChannelPipeline.java:173)

私は正しくやっていますか?

ありがとう

4

1 に答える 1

3

io.netty.handler.timeout.ReadTimeoutHandler の同じインスタンスを多くのチャネルに追加しているようです。試す

ch.pipeline()
.addLast(new ReadTimeoutHandler(3000))

@Sharable のドキュメント:

/**
 * Indicates that the same instance of the annotated {@link ChannelHandler}
 * can be added to one or more {@link ChannelPipeline}s multiple times
 * without a race condition.
 * <p>
 * If this annotation is not specified, you have to create a new handler
 * instance every time you add it to a pipeline because it has unshared
 * state such as member variables.
 * <p>
 * This annotation is provided for documentation purpose, just like
 * <a href="http://www.javaconcurrencyinpractice.com/annotations/doc/">the JCIP annotations</a>.
 */
@Inherited
@Documented
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
@interface Sharable {
    // no value
}
于 2012-12-12T09:45:23.693 に答える