InetAddress.getLocalHost() slow to run (30+ seconds)
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)
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.