最近在学习Java AIO操作时,出现如下异常

比较奇怪的是,该异常仅仅在两个操作间隔非常短的时候,才会出现。根据调式与排查,发现问题出现在AsynchronousSocketChannel的connect方法调用上。

/*** Connects this channel.** <p> This method initiates an operation to connect this channel. This* method behaves in exactly the same manner as the {@link* #connect(SocketAddress, Object, CompletionHandler)} method except that* instead of specifying a completion handler, this method returns a {@code* Future} representing the pending result. The {@code Future}'s {@link* Future#get() get} method returns {@code null} on successful completion.** @param   remote*          The remote address to which this channel is to be connected** @return  A {@code Future} object representing the pending result** @throws  UnresolvedAddressException*          If the given remote address is not fully resolved* @throws  UnsupportedAddressTypeException*          If the type of the given remote address is not supported* @throws  AlreadyConnectedException*          If this channel is already connected* @throws  ConnectionPendingException*          If a connection operation is already in progress on this channel* @throws  SecurityException*          If a security manager has been installed*          and it does not permit access to the given remote endpoint*/public abstract Future<Void> connect(SocketAddress remote);

此处connect为异步方法,调用connect时,可能并没有成功建立连接,从而导致出现上述异常。
解决措施:
1、显示调用get,通过阻塞的方式,获取连接。

2、通过如下connect方法,通过第三个参数,在完成连接连接时,进行后续操作。

public abstract <A> void connect(SocketAddress remote,A attachment,CompletionHandler<Void,? super A> handler);

java.nio.channels.NotYetConnectedException: null相关推荐

  1. java.nio.channels.UnresolvedAddressException: null [运行storm-0.9.4集群时]

    [问题描述] 在运行storm集群时,发现kafkaspout不能消费kafka的数据,查看stormUI,没有发现有什么异常,但是手动消费kafka的数据又是正确的,通过一步一步问题排查,最好定位到 ...

  2. Netty 中 IOException: Connection reset by peer 与 java.nio.channels.ClosedChannelException: null

    最近发现系统中出现了很多 IOException: Connection reset by peer 与 ClosedChannelException: null 深入看了看代码, 做了些测试, 发现 ...

  3. grpc报错: java.nio.channels.UnresolvedAddressException : null

    出现该问题是因为在构建grpc client时,将grpc server地址写为域名的格式,但是该域名与ip地址的映射关系没有在hosts文件或者dns中配置,这就导致域名解析失败. 解决方法一:在h ...

  4. Spark2 Failed to send RPC 5346982634 to /ns1:58312: java.nio.channels.ClosedChannelException

    将spark任务运行与yarn上出现以下错误: scala> 18/11/21 16:20:11 ERROR cluster.YarnClientSchedulerBackend: Yarn a ...

  5. sparkStreaming+kafka SparkException: java.nio.channels.ClosedChannelException异常报错

    在运行sparkStreaming+kafka的时候报错 java io报错, 如果broker-list的端口不对或者kafka服务端未启动,会遇到以下错误: Exception in thread ...

  6. 【Hadoop】java.io.IOException: Failed on local exception: java.nio.channels.ClosedByInterruptException

    查看日志中的报错信息如下: java.io.IOException: Failed on local exception: java.nio.channels.ClosedByInterruptExc ...

  7. java.nio.channels.UnresolvedAddressException

    RocketMq和Redis的netty版本冲突 报错信息如下 排查原因 解决办法 分析 报错信息如下 java.nio.channels.UnresolvedAddressException - U ...

  8. 【NIO】解读 java.nio.channels.Selector

    目录 Part 1. What's Selector? Part 2. Why Selector? Part 3. How to use Selector? 1) Create Selector 2) ...

  9. Spark报错 Failed to send RPC xxx to/ip:43074 java.nio.channels.ClosedChannelException

    1.美图 2.背景 是这样的,我写了一个spark程序,然后,运行的时候,我kiill yarn掉这个程序,然后发现程序报个错然后继续运行了. 我在页面点击任务停止就没事,我页面点击是调用yarn a ...

  10. java中channel的作用,java.nio.channels包中的FileChannel类的作用是()。

    一旦计算机感染了病毒,即使用防病毒程序检测到它,如果不进行计算机的全部扫描,也不可能做到完全无毒. Koreaisnolongeradeveloping country,butPeoplestillp ...

最新文章

  1. 图说子图同构算法——VF2算法(一)
  2. CISCO CME:配置基于硬件的电话会议
  3. python计数属性类
  4. 2014年第五届蓝桥杯C/C++ A组国赛 —— 第四题:排列序数
  5. JAVA面试常考系列十
  6. 引入antd组件样式_个人作品:一个技术栈koa2+ mysql+react + antd的个人博客
  7. 一起教育科技登陆纳斯达克:首日股价上涨0.67%
  8. CN笔记:第一章 计算机网络概述
  9. 谈java的导入(import)
  10. Python基础知识之面向对象编程
  11. 有限元法 matlab,MATLAB有限元分析与应用.pdf
  12. 100道c语言经典编程题,C语言经典例题100道
  13. gdp python 变迁动图_十分钟,用 Python 带你看遍 GDP 变迁
  14. Linux配置SSH免密码登录(非root账号)
  15. oracle批次处理数据_如何加速Oracle大批量数据处理
  16. docker笔记之具名挂载与匿名挂载
  17. 【问题解决方法】java词云库kumo色差
  18. Lua 错误之 attempt to index a function value
  19. [转]情侣相处最佳模式
  20. 通达信股票的量化分析模型的公式

热门文章

  1. c语言中断的作用,什么是中断?
  2. 泰戈尔《园丁集》选段
  3. android 图片编辑工具,照片编辑器:Photo Editor
  4. 读书笔记(十二)--穷爸爸,富爸爸
  5. 自动控制系统中的典型环节
  6. 怎么让背景铺满整个页面_word怎么让背景图片铺满整个页面
  7. 阿里云虚拟主机和服务器的区别
  8. SQL Server 2014 企业版安装教程
  9. sis最新地址获取方法_微信表情悄悄更新,获取最新表情方法!
  10. python编写直角三角形边长公式_python 打印直角三角形,等边三角形,菱形,正方形的代码...