av一区二区在线观看_亚洲男人的天堂网站_日韩亚洲视频_在线成人免费_欧美日韩精品免费观看视频_久草视

您的位置:首頁技術文章
文章詳情頁

java - Netty的future.channel().closeFuture().sync();到底有什么用?

瀏覽:105日期:2023-12-21 08:06:09

問題描述

我看到很多Netty的例子都在末尾加上了這句話:future.channel().closeFuture().sync();

比如:

public class TimeServer { private int count = 0; public void bind(int port) {try { EventLoopGroup bossGroup = new NioEventLoopGroup(); EventLoopGroup workGroup = new NioEventLoopGroup(); ServerBootstrap b = new ServerBootstrap(); // (2) b.group(bossGroup, workGroup).channel(NioServerSocketChannel.class) // (3) .childHandler(new ChannelInitializer<SocketChannel>() {@Overrideprotected void initChannel(SocketChannel arg0) throws Exception { arg0.pipeline().addLast(new LineBasedFrameDecoder(1024)); arg0.pipeline().addLast(new StringDecoder()); arg0.pipeline().addLast(new ChannelInboundHandlerAdapter() {@Overridepublic void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception { // ByteBuf buf = (ByteBuf) msg; // byte[] req = new // byte[buf.readableBytes()]; // buf.readBytes(req); // String body = new String(req, 'UTF-8'); System.out.println( 'The Time Server Received order:' + msg + '; the counter is:' + ++count); // String currentTime = 'QUERY TIME // ORDER'.equalsIgnoreCase(body) // ? new // Date(System.currentTimeMillis()).toString() // : 'BAD ORDER'; // // currentTime = currentTime + // System.getProperty('line.separator'); // ByteBuf resp = // Unpooled.copiedBuffer(currentTime.getBytes()); // ctx.writeAndFlush(resp);} });} }); ChannelFuture future = b.bind(port).sync(); System.out.println('Server start listen at ' + port); future.channel().closeFuture().sync();System.out.println('執行到這里 ' + port);} catch (InterruptedException e) { e.printStackTrace();} } public static void main(String[] args) {new TimeServer().bind(10000); }}

但是我看這行代碼一直沒有執行。請問這是怎么回事呢?

問題解答

回答1:

不是沒執行,是主線程到這里就 wait 子線程退出了,子線程才是真正監聽和接受請求的。

標簽: java
相關文章:
主站蜘蛛池模板: 日韩午夜影院 | 日韩国产在线 | 国产精品成人一区二区三区夜夜夜 | 大象视频一区二区 | 成人看片在线观看 | 久久亚洲一区二区三区四区 | 99reav| 中文字幕影院 | 一级毛片免费完整视频 | 亚洲激情专区 | 精品九九 | 欧美日韩精品专区 | 国产精品久久久久久久免费观看 | 三级黄片毛片 | 天天干夜夜操 | 国产一区精品在线 | 色免费在线视频 | 99久久精品免费看国产小宝寻花 | 亚洲三区视频 | 国产精品区二区三区日本 | 二区视频 | 国产一区二区三区高清 | 久久麻豆精品 | 超碰精品在线 | 久久久久久国产精品 | 神马影院一区二区三区 | 97av在线| 中文字幕日韩一区 | av看片网站| 日本一区二区三区四区 | 久久久久亚洲精品 | 国产激情视频在线免费观看 | 天天操夜夜操 | 国产视频一区二区在线观看 | 欧美aaa| 国产一区视频在线 | 亚洲国产免费 | 性欧美hd| 黄色综合 | 一区二区日本 | 亚洲精品一区二区三区蜜桃久 |