亚洲精品久久久中文字幕-亚洲精品久久片久久-亚洲精品久久青草-亚洲精品久久婷婷爱久久婷婷-亚洲精品久久午夜香蕉

您的位置:首頁技術(shù)文章
文章詳情頁

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

瀏覽:79日期: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('執(zhí)行到這里 ' + port);} catch (InterruptedException e) { e.printStackTrace();} } public static void main(String[] args) {new TimeServer().bind(10000); }}

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

問題解答

回答1:

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

標(biāo)簽: java
相關(guān)文章:
主站蜘蛛池模板: 国产在线观看a | 香蕉爱视频 | 国内精品久久久久影院老司 | 国内永久第一免费福利视频 | 国产成人精品一区二三区在线观看 | 国产一区二区三区久久精品 | 黑人激情视频 | 国产成人影院 | caob视频| 青草久久久 | 国产精品久久久久国产精品 | 日韩欧美精品 | 久久精品免费 | 久久综合九色综合欧美9v777 | 成人满18在线观看网站免费 | 1000部禁片黄的免费看 | 小明永久2015www永久免费观看 | 在线欧洲成人免费视频 | 亚洲欧美日韩中文综合在线不卡 | 91情侣在线偷精品国产 | 亚洲 中文 欧美 日韩 在线人 | 国产成人久久精品二区三区 | 国产精品久久久99 | 欧美操片在线观看 | 免费视频爰爱太爽了 | 亚洲国产第一区二区三区 | 亚洲无线码一区二区三区在线观看 | 日韩在线 中文字幕 | 国产xx视频 | 999久久久精品视频在线观看 | 色噜噜五月综合激情久久爱 | 国产污视频在线播放 | 国产欧美日韩精品a在线观看高清 | 成人卡通精品卡通动漫第一页 | 91啦在线视频| 免费视频精品一区二区 | 亚洲黄色高清 | a毛片免费在线观看 | 日韩免费高清一级毛片 | 日韩免费片 | 91老色批网站免费看 |