Netty在linux启动很慢的问题

背景
  1. 最近有构建一个netty的http服务,在本地启动正常,没有问题,但是放在了虚拟机,突然发现,很慢,启动很慢,开始怀疑是不是自己写的代码太垃圾了,导致启动很慢.启动要100多秒(1分钟钟算长了哦).

2.问题排查
第一步:关闭ipv6,因为之前的vertx 就出现ipv6导致启动很慢,先关了再说

java -jar    -Djava.net.preferIPv4Stack=true ***.jar 

结果:然并*
** 第二步骤 **:查看线程状态,看RUNABLE状态线程在哪一步卡着

jstack pid

结果:发现停留在获取hostname这一段

"main" #1 prio=5 os_prio=0 tid=0x00007f179c008800 nid=0x686 runnable [0x00007f17a5b27000]
   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 <0x00000000f60753f8> (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.(ApplicationPid.java:46)
        at org.springframework.boot.logging.LoggingSystemProperties.apply(LoggingSystemProperties.java:106)
        at org.springframework.boot.logging.LoggingSystemProperties.apply(LoggingSystemProperties.java:99)
        at org.springframework.boot.context.logging.LoggingApplicationListener.initialize(LoggingApplicationListener.java:259)
        at org.springframework.boot.context.logging.LoggingApplicationListener.onApplicationEnvironmentPreparedEvent(LoggingApplicationListener.java:228)
        at org.springframework.boot.context.logging.LoggingApplicationListener.onApplicationEvent(LoggingApplicationListener.java:201)
        at org.springframework.context.event.SimpleApplicationEventMulticaster.doInvokeListener(SimpleApplicationEventMulticaster.java:172)
        at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:165)
        at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:139)
        at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:127)
        at org.springframework.boot.context.event.EventPublishingRunListener.environmentPrepared(EventPublishingRunListener.java:75)
        at org.springframework.boot.SpringApplicationRunListeners.environmentPrepared(SpringApplicationRunListeners.java:54)
        at org.springframework.boot.SpringApplication.prepareEnvironment(SpringApplication.java:347)
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:306)
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:1260)
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:1248)
        at com.anyly.ApplicationService.main(ApplicationService.java:27)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:498)
        at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:48)
        at org.springframework.boot.loader.Launcher.launch(Launcher.java:87)
        at org.springframework.boot.loader.Launcher.launch(Launcher.java:50)
        at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:51)

网上说需要检查 /etc/hosts 看本机的hostname 是否映射了,
仔细一看,确实没有
赶紧添加

1.查看本机hostname 
linux 命令:  hostname
2.  添加
vi /etc/hosts  

3.添加
127.0.0.1   hostname(刚才显示的哦)
::1         hostname

你可能感兴趣的:(Netty在linux启动很慢的问题)