InetAddress.getLocalHost() slow to run (30+ seconds)

后端 未结 5 2119
独厮守ぢ
独厮守ぢ 2020-11-28 06:19

With the following code:

try {
  System.out.println(new Date());
  InetAddress hostName = InetAddress.getLocalHost();
  System.out.println(new Date());
} cat         


        
5条回答
  •  死守一世寂寞
    2020-11-28 06:25

    This problem appears on MacOS Sierra using Java8, updates equals or bigger than 60 (jdk1.8.0_60.jdk, jdk1.8.0_77.jdk, etc).

    The solution can be found here: https://github.com/thoeni/inetTester.

    This is the content of my /etc/hosts file:

    127.0.0.1   localhost mac.local
    ::1         localhost mac.local
    

    In my case, mac is my computer name.

提交回复
热议问题