RuntimeMXBean.getName () freezes on Mac OS X Sierra - how to fix?

If I run the following in OS X Sierra (JDK 8u111), it takes 5 seconds to start (unlike milliseconds, for example, Linux):

import java.lang.management.ManagementFactory; import java.lang.management.RuntimeMXBean; public class BeanTest { public static void main (String[] args) { RuntimeMXBean bean = ManagementFactory.getRuntimeMXBean(); System.out.println(bean.getName()); } } 

This causes a significant slowdown in the use of libraries whose newer versions call this bit of the management API. My first thought is that this is a DNS problem (the computer is on local home NAT), but my attempt to resolve either the local host name or my local IP address in the shell returns a response (NXDOMAIN) instantly. Running dtruss on a Java process caused these lines to repeat continuously for a 5 second lag:

  782/0x36f5: psynch_cvwait(0x7FEE4170B968, 0x20100000300, 0x200) = -1 Err#316 782/0x36f5: gettimeofday(0x7000039B4938, 0x0, 0x0) = 0 0 

What is going on here and what can I do to unlock this bottleneck?

+6
source share
1 answer

I fix the problem manually by setting HostName to LocalHostName, before this HostName is not set:

 $ scutil --set HostName $(scutil --get LocalHostName) 
0
source

Source: https://habr.com/ru/post/1013841/


All Articles