目錄
說明
最近部署一個項(xiàng)目到centOS上時,項(xiàng)目啟動運(yùn)行,中間會卡住一段時間,將近2,3分鐘。看日志沒有報錯。同樣的包,在另外一臺機(jī)子部署后啟動又是正常的。
排查
百度了一圈。網(wǎng)上大部份都說random的原因, 我都照著改了,但是,依然很慢。
于是去問我們部門大大牛;大牛說你用jstack看一下日志了嗎???我:…
沒用過jstack調(diào)試工具;于是,又開始漫長的度娘了。
jstack調(diào)試
在程序啟動之后,立即執(zhí)行:
ps -aux
|grep 程序名稱
得到進(jìn)程pid;
然后執(zhí)行jstack命令,監(jiān)控jvm狀態(tài):
jstack -l 進(jìn)程id
jstack的日志大致如下:
卡住的時候關(guān)鍵log是一下這一段:
"main" java.lang.Thread.State: RUNNABLEat java.net.Inet6AddressImpl.lookupAllHostAddr
(Native Method
)at java.net.InetAddress
$2.lookupAllHostAddr
(InetAddress.java:929
)at java.net.InetAddress.getAddressesFromNameService
(InetAddress.java:1324
)at java.net.InetAddress.getLocalHost
(InetAddress.java:1501
)- locked
<0x00000000fd466af
8> (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:54
)at org.springframework.boot.system.ApplicationPid.
<init
>(ApplicationPid.java:45
)at org.springframework.boot.logging.LoggingSystemProperties.apply
(LoggingSystemProperties.java:123
)at org.springframework.boot.logging.AbstractLoggingSystem.applySystemProperties
(AbstractLoggingSystem.java:177
)at org.springframework.boot.logging.Slf4JLoggingSystem.loadConfiguration
(Slf4JLoggingSystem.java:61
)at org.springframework.boot.logging.logback.LogbackLoggingSystem.loadConfiguration
(LogbackLoggingSystem.java:151
)at org.springframework.boot.logging.AbstractLoggingSystem.initializeWithConventions
(AbstractLoggingSystem.java:80
)at org.springframework.boot.logging.AbstractLoggingSystem.initialize
(AbstractLoggingSystem.java:60
)at org.springframework.boot.logging.logback.LogbackLoggingSystem.initialize
(LogbackLoggingSystem.java:118
)at org.springframework.boot.context.logging.LoggingApplicationListener.initializeSystem
(LoggingApplicationListener.java:313
)at org.springframework.boot.context.logging.LoggingApplicationListener.initialize
(LoggingApplicationListener.java:288
)at org.springframework.boot.context.logging.LoggingApplicationListener.onApplicationEnvironmentPreparedEvent
(LoggingApplicationListener.java:246
)at org.springframework.boot.context.logging.LoggingApplicationListener.onApplicationEvent
(LoggingApplicationListener.java:223
)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:76
)at org.springframework.boot.SpringApplicationRunListeners.environmentPrepared
(SpringApplicationRunListeners.java:53
)at org.springframework.boot.SpringApplication.prepareEnvironment
(SpringApplication.java:345
)at org.springframework.boot.SpringApplication.run
(SpringApplication.java:308
)at org.springframework.boot.SpringApplication.run
(SpringApplication.java:1226
)at org.springframework.boot.SpringApplication.run
(SpringApplication.java:1215
)at ctsi.riverchief.eureka.EurekaApplication.main
(EurekaApplication.java:12
)Locked ownable synchronizers:- None
"VM Thread" os_prio=0 tid=0x00007f3990256800
nid=0x276bb runnable
這個錯誤的原因是因?yàn)閔osts和hostname不一致導(dǎo)致的;
解決方法
查看本機(jī)的hostname:
[zjsl@host-192-168-* etc
]$
hostname
查看/etc/hosts文件內(nèi)容:
[zjsl@host-192-168-* etc
]$
cat /etc/hosts
這里就發(fā)現(xiàn)hosts文件真的沒有配置本機(jī)的hostname映射;
往hosts里面添加一行到本機(jī)的hostname映射(需要root權(quán)限)
vi /etc/hosts
保存后,重啟網(wǎng)絡(luò):
service network restart
重試項(xiàng)目啟動,問題解決!!!
參考:Centos 啟動Spring boot項(xiàng)目慢的原因
總結(jié)
以上是生活随笔為你收集整理的springboot项目部署后项目启动慢的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。