不知道从什么时候Mac启动Java很慢,一开始还以为是电脑用久了,实际上是因为获取主机IP地址时耗时很长
直接分析Java的线程栈,发现线程一直在执行java.net.Inet6AddressImpl.lookupAllHostAddr(Native Method)
"main" #1 prio=5 os_prio=31 tid=0x00007fe0e1000000 nid=0x2503 runnable [0x000070000b9c3000]
java.lang.Thread.State: RUNNABLE
at java.net.Inet6AddressImpl.lookupAllHostAddr(Native Method)
at java.net.InetAddress$2.lookupAllHostAddr(InetAddress.java:928)
at java.net.InetAddress.getAddressesFromNameService(InetAddress.java:1323)
at java.net.InetAddress.getLocalHost(InetAddress.java:1500)
- locked <0x00000007403c92a0> (a java.lang.Object)
at sun.management.VMManagementImpl.getVmId(VMManagementImpl.java:140)
at sun.management.RuntimeImpl.getName(RuntimeImpl.java:59)
at org.springframework.boot.system.ApplicationPid.getPid(ApplicationPid.java:55)
at org.springframework.boot.system.ApplicationPid.<init>(ApplicationPid.java:46)
at org.springframework.boot.logging.LoggingSystemProperties.apply(LoggingSystemProperties.java:106)
at org.springframework.boot.logging.AbstractLoggingSystem.applySystemProperties(AbstractLoggingSystem.java:183)
at org.springframework.boot.logging.Slf4JLoggingSystem.loadConfiguration(Slf4JLoggingSystem.java:61)
修改/etc/hosts
# Localhost (DO NOT REMOVE) Start
127.0.0.1 localhost
::1 localhost
::1 ip6-localhost
::1 ip6-loopback
# Localhost (DO NOT REMOVE) End