在学习java nio的过程中发现某些情况下使用该方法会导致程序阻塞,(情况:服务器,Linux;客户端,WIN10)
java.net.InetAddress.getHostName()
阻塞情况如下:
"TCP:Selector@server:/192.168.0.117:18300" prio=6 tid=0x0000000007eff800 nid=0x3674 runnable [0x00000000093ae000]
java.lang.Thread.State: RUNNABLE
at java.net.Inet6AddressImpl.getHostByAddr(Native Method)
at java.net.InetAddress$1.getHostByAddr(InetAddress.java:880)
at java.net.InetAddress.getHostFromNameService(InetAddress.java:559)
at java.net.InetAddress.getHostName(InetAddress.java:502)
at java.net.InetAddress.getHostName(InetAddress.java:474)
at com.gifisan.nio.component.AbstractEndPoint.getRemoteHost(AbstractEndPoint.java:69)
at com.gifisan.nio.component.AbstractEndPoint.toString(AbstractEndPoint.java:90)
at com.gifisan.nio.common.MessageFormatter.safeObjectAppend(MessageFormatter.java:138)
at com.gifisan.nio.common.MessageFormatter.deeplyAppendParameter(MessageFormatter.java:110)
at com.gifisan.nio.common.MessageFormatter.arrayFormat(MessageFormatter.java:68)
at com.gifisan.nio.common.MessageFormatter.format(MessageFormatter.java:16)
at com.gifisan.nio.component.IOSession.toString(IOSession.java:245)
at org.slf4j.helpers.MessageFormatter.safeObjectAppend(MessageFormatter.java:304)
at org.slf4j.helpers.MessageFormatter.deeplyAppendParameter(MessageFormatter.java:276)
at org.slf4j.helpers.MessageFormatter.arrayFormat(MessageFormatter.java:230)
at org.slf4j.helpers.MessageFormatter.format(MessageFormatter.java:124)
at org.slf4j.impl.Log4jLoggerAdapter.debug(Log4jLoggerAdapter.java:228)
at com.gifisan.nio.common.SLF4JLogger.debug(SLF4JLogger.java:45)
at com.gifisan.nio.component.LoggerSEtListener.sessionOpened(LoggerSEtListener.java:11)
at com.gifisan.nio.component.SessionEventListenerWrapper.sessionOpened(SessionEventListenerWrapper.java:22)
at com.gifisan.nio.component.DefaultTCPEndPoint.<init>(DefaultTCPEndPoint.java:55)
at com.gifisan.nio.connector.TCPSelectionConnector.attachEndPoint(TCPSelectionConnector.java:50)
at com.gifisan.nio.connector.TCPSelectionConnector.finishConnect(TCPSelectionConnector.java:66)
at com.gifisan.nio.connector.TCPSelectionConnector.accept(TCPSelectionConnector.java:40)
at com.gifisan.nio.component.TCPSelectorLoop.accept(TCPSelectorLoop.java:40)
at com.gifisan.nio.component.AbstractSelectorLoop.loop(AbstractSelectorLoop.java:45)
at com.gifisan.nio.component.concurrent.UniqueThread.loop(UniqueThread.java:44)
at com.gifisan.nio.component.concurrent.UniqueThread$1.run(UniqueThread.java:30)
at java.lang.Thread.run(Thread.java:662)
Locked ownable synchronizers:
- None
网上找了下有人说是jdk的bug,不过这为直接crashes了,
http://bugs.java.com/bugdatabase/view_bug.do?bug_id=6487744
ITEYE:
http://jiajianchao-gmail-com.iteye.com/blog/1597253