私はネット初心者です。これは予想される動作ですか?
もう少し詳しく:
public class Test {
public static void connect(){
EventLoopGroup workerGroup = new NioEventLoopGroup();
Bootstrap bs = new Bootstrap();
bs.group(workerGroup);
bs.channel(NioSocketChannel.class);
bs.option(ChannelOption.CONNECT_TIMEOUT_MILLIS, 10000);
bs.handler( new ChannelInitializer<SocketChannel>(){
@Override
protected void initChannel(SocketChannel ch) throws Exception {
ChannelPipeline pl = ch.pipeline();
pl.addLast("readTimeoutHandler", new ReadTimeoutHandler(1000,
TimeUnit.MILLISECONDS));
pl.addLast("framer", new DelimiterBasedFrameDecoder(
16384, Delimiters.lineDelimiter()));
pl.addLast("string-decoder", new StringDecoder());
pl.addLast("handler",
new SimpleChannelInboundHandler<String> (String.class){
@Override
protected void channelRead0(ChannelHandlerContext ctx,
String msg) throws Exception {
System.out.println(msg);
}
@Override
protected void exceptionCaught(ChannelHandlerContext ctx,
Throwable cause) throws Exception {
if(cause instanceof ReadTimeoutException){
System.out.println("Timed out.");
}
ctx.close();
}
});
}
});
bs.connect("127.0.0.1", 45001);
}
}
これは単なるテストケースなので、少し間違っているかもしれませんが、パイプラインは私の実際のパイプラインに十分に似ています。
基本的に、他に何も触れずにEventLoopGroup
初期化を からに変更NioEventLoopGroup
しOioEventLoopGroup
、ブートストラップ チャネルの設定を からbootstrap.channel(NioSocketChannel.class)
に変更すると、 のスローが停止します。bootstrap.channel(OioSocketChannel.class)
ReadTimeoutHandler
ReadTimeoutExceptions