future.channel().closeFuture().sync();后面代码不执行
来源:互联网 发布:qc数据库 编辑:程序博客网 时间:2024/05/15 23:44
在使用netty框架时:
Netty是基于Java NIO的网络通信框架.
public RpcResponse send(RpcRequest request) throws Exception { EventLoopGroup group = new NioEventLoopGroup(); try { Bootstrap bootstrap = new Bootstrap(); bootstrap.group(group).channel(NioSocketChannel.class) .handler(new ChannelInitializer<SocketChannel>() { @Override public void initChannel(SocketChannel channel) throws Exception { // 向pipeline中添加编码、解码、业务处理的handler channel.pipeline() .addLast(new RpcEncoder(RpcRequest.class)) //OUT - 1 .addLast(new RpcDecoder(RpcResponse.class)) //IN - 1 .addLast(RpcClient.this); //IN - 2 } }).option(ChannelOption.SO_KEEPALIVE, true); // 链接服务器 ChannelFuture future = bootstrap.connect(host, port).sync(); //将request对象写入outbundle处理后发出(即RpcEncoder编码器) future.channel().writeAndFlush(request).sync(); // 用线程等待的方式决定是否关闭连接 // 其意义是:先在此阻塞,等待获取到服务端的返回后,被唤醒,从而关闭网络连接 synchronized (obj) { obj.wait(); } if (response != null) { //服务器同步连接断开时,这句代码才会往下执行 future.channel().closeFuture().sync(); } return response; } finally { group.shutdownGracefully(); } }
//也就是服务端执行完这一句:ctx.writeAndFlush(response).addListener(ChannelFutureListener.CLOSE);
//服务端的这句代码才会往下执行
future.channel().closeFuture().sync();
0 0
- future.channel().closeFuture().sync();后面代码不执行
- c # 在cs代码中间“提示控制” 后面的执行不执行 (老七的原版)
- IOS 中 main()函数中UIApplicationMain后面的代码不执行...
- PHP 代码延时执行后面的代码
- return命令--后面的程序不执行
- Python--函数return后面的语句不执行
- golang中并发sync和channel
- golang中并发sync和channel
- golang中并发sync和channel
- golang中并发sync和channel
- golang中并发sync和channel
- php require_once()引入文件后,后面的代码无法执行
- java抛出异常后面的代码是否能执行?
- java 抛出异常后,还会执行后面代码吗?
- monkeyrunner raw_input()接收输入后不运行后面的代码
- dwr java代码不执行
- js代码不执行问题
- iframe必合写法不标准造成标签后面js alert不执行
- getParameterValues和getParameter的区别
- [LeetCode]389. Find the Difference(找不同)
- react native开发:实现点击左侧选择项,右侧显示内容的功能
- java.lang.ClassNotFoundException: com.fasterxml.jackson.core.JsonProcessingException
- 纯css实现进度条效果
- future.channel().closeFuture().sync();后面代码不执行
- 盒模型代码简写
- Mysql limit 分页机制和优化实例
- 你什么都没错,只是太老了。
- Json对象与Json字符串互转(4种转换方式)
- hduoj-5444【二叉树构造】
- c与c++区别之this指针的巧妙应用
- 杭电 2044 一只小蜜蜂 斐波那契数列
- 杭电 1563 Find your present!