首页 > 代码库 > JDK NIO SelectionKey bug

JDK NIO SelectionKey bug

此bug项目中使用elasticSearch中出现的,原因是,nio事件选择器,在特性内核下以及jdk6版本中,出现不hold线程,死循环获取事件的bug,导致cup使用率过高;

此bug在官网已被修复:http://bugs.java.com/bugdatabase/view_bug.do?bug_id=6403933

 

如果不升级版本,

System.setProperty(“org.elasticsearch.common.netty.epollBugWorkaround”,true); 增加此句代码。

官网修复解决:取消了选择器,创建一个新的。

if (SelectionKey != null)  {  // the key you registered on the temporary selector   SelectionKey.cancel();   // cancel the SelectionKey that was registered with the temporary selector   // flush the cancelled key   temporarySelector.selectNow();} which is safe. Now everything works fine.

JDK NIO SelectionKey bug