InetAddressImpl#lookupAllHostAddr慢/挂起
生活随笔
收集整理的這篇文章主要介紹了
InetAddressImpl#lookupAllHostAddr慢/挂起
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
自從我升級到優勝美地以來,我已經注意到嘗試解析我的家庭網絡上的本地主機已經花費了很多時間(有時超過一分鐘),所以我想我會嘗試找出原因。
這是我的初始/ etc / hosts文件的外觀,它基于我的機器的主機名是teetotal的假設:
$ cat /etc/hosts ## # Host Database # # localhost is used to configure the loopback interface # when the system is booting. Do not change this entry. ## 127.0.0.1 localhost 255.255.255.255 broadcasthost ::1 localhost #fe80::1%lo0 localhost 127.0.0.1 wuqour.local 127.0.0.1 teetotal我設置了一個測試來重現該問題:
import java.net.InetAddress; import java.net.UnknownHostException;public class LocalhostResolution {public static void main( String[] args ) throws UnknownHostException{long start = System.currentTimeMillis();InetAddress localHost = InetAddress.getLocalHost();System.out.println(localHost);System.out.println(System.currentTimeMillis() - start);} }具有以下輸出:
Exception in thread "main" java.net.UnknownHostException: teetotal-2: teetotal-2: nodename nor servname provided, or not knownat java.net.InetAddress.getLocalHost(InetAddress.java:1473)at LocalhostResolution.main(LocalhostResolution.java:9)at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)at java.lang.reflect.Method.invoke(Method.java:606)at com.intellij.rt.execution.application.AppMain.main(AppMain.java:134) Caused by: java.net.UnknownHostException: teetotal-2: nodename nor servname provided, or not knownat java.net.Inet6AddressImpl.lookupAllHostAddr(Native Method)at java.net.InetAddress$1.lookupAllHostAddr(InetAddress.java:901)at java.net.InetAddress.getAddressesFromNameService(InetAddress.java:1293)at java.net.InetAddress.getLocalHost(InetAddress.java:1469)... 6 more不知何故,我的主機名已更改為teetotal-2,因此我在/ etc / hosts中添加了以下條目:
127.0.0.1 teetotal-2現在,如果我們運行程序,則會看到以下輸出:
teetotal-2/127.0.0.1 5011解決該問題仍需要5秒鐘,這比我預期的要長得多。 中斷代碼后,似乎正在嘗試執行IPv6解析而不是IPv4解析,因此我也為此添加了/ etc / hosts條目:
::1 teetotal-2現在解析速度更快:
teetotal-2/127.0.0.1 6快樂的時光!
翻譯自: https://www.javacodegeeks.com/2015/03/inetaddressimpllookupallhostaddr-slowhangs.html
總結
以上是生活随笔為你收集整理的InetAddressImpl#lookupAllHostAddr慢/挂起的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 香辣弹簧:自动接线的不同方法
- 下一篇: 为JPA的本机查询API键入安全查询