Jvm takes a long time to resolve ip-address for localhost Jvm takes a long time to resolve ip-address for localhost java java

Jvm takes a long time to resolve ip-address for localhost


I had the same problem. Tomcat went from 15 seconds to 6 minutes to initialise spring context after the upgrade... disabling csrutils didn't solve the issue for me.

I solved the problem by adding my Mac hostname (i.e. Macbook.local, or whatever your Mac is called) on the /etc/hosts file mapped to the 127.0.0.1 address as well as the ::1 like this:

127.0.0.1   localhost mbpro.local::1         localhost mbpro.local

If you're interested you can find some details on the issue and solution here:https://thoeni.io/post/macos-sierra-java/

On the post I also link to a github project to help troubleshooting the issue and validating the solution.

The problem is related (I believe) on how the localhost name resolution works and how the java.net.InetAddr class is retrieving the addresses. I verified with few colleagues and apparently it doesn't happen to everyone who upgraded to Sierra, but I'm still investigating the roots of this change.

The solution anyway was the same that antid0te implemented and worked immediately.


Correct answer: Jvm takes a long time to resolve ip-address for localhost

For the lazy people:

sudo sed -i bak "s^127\.0\.0\.1.*^127.0.0.1 localhost $(hostname)^g" /etc/hostssudo sed -i bak "s^::1.*^::1 localhost $(hostname)^g" /etc/hostssudo ifconfig en0 downsudo ifconfig en0 up


I have the same problem. My spring-boot application take 60 seconds to start on Sierra against 25 seconds on Yosemite.

While debugging, I realized that the problem comes from InetAddress.getLocalHost().I changed my host file to add my hostname for 127.0.0.1 and :: 1 and now the application starts as fast as before.