InetAddress.getLocalHost() slow to run (30+ seconds)
The above answer works on my mac, you can try it like this:
step 1, download inetTester.jar from thoeni/inetTester
step 2, run it on your mac. here is the result on my mac:
$ java -jar ./inetTester.jar
Calling the hostname resolution method...
Method called, hostname MacBook-Pro.local, elapsed time: 5009 (ms)
it takes 5s to run the test, and it shows the hostname of my mac.
step 3, modify the /etc/hosts:
127.0.0.1 MacBook-Pro.local
::1 MacBook-Pro.local
the host is what shows in step 2. and after this, run the test again:
$ java -jar ./inetTester.jar
Calling the hostname resolution method...
Method called, hostname MacBook-Pro.local, elapsed time: 6 (ms)
yeah, it comes with only 6ms.
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.
The issue can be solved by adding the following to /etc/hosts
(assuming output of hostname
command is my-macbook
:
127.0.0.1 my-macbook
::1 my-macbook
This returns the time to something more suitable (< 1 second)