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

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

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

瀏覽:107日期: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
相關文章:
主站蜘蛛池模板: 精品国产精品国产 | 欧美日韩一区二区三区免费 | 国产精品人人视频 | 国产在线一区二区视频 | 不卡视频一区 | 国产精品久久久久亚洲 | 在线免费看影视网站入口 | 日韩成人在线播放 | 精品久久久久久久久久久 | 久久精品国产免费观看99 | 91久久综合| 国产一级片网址 | www.香蕉视频在线观看 | 在线一区免费播放 | 成人短视频在线在线观看 | 亚洲黄色在线观看 | 在线观看久草视频 | 嘿咻18视频在线看 | 国语对白avxxxooo | 久久久精品午夜免费不卡 | 一本大道一卡二卡入口2021 | 18年大片免费在线观看 | 成人福利免费视频 | 一级片在线观看 | 女人色毛片女人色毛片中国 | 69成人做爰免费视频 | 欧美成人一级片 | 亚洲精品视频在线 | 久久窝窝国产精品午夜看15 | 国产午夜精品久久久久免费视 | 成人久久18免费网址 | 草逼视频网址 | 色婷婷狠狠久久综合五月 | 日本免费大黄在线观看 | 免费看一级欧美毛片视频 | 久久精品在线播放 | 亚洲xxxx视频 | 成人欧美视频在线观看播放 | 日韩精品欧美在线 | 精品国产成人 | 久久精品综合国产二区 |