Tomcat 啟動卡在 Root WebApplicationContext: initialization completed in


tomcat 啟動一直卡在

Root WebApplicationContext: initialization completed in

重啟了很多次,更換jdk版本,tomcat版本都不行。

tomcat所在的JVM進程已經被啟動了所以可以排除是JVM退出引起的問題。那么問題真的就是JVM因為某種原因被阻塞了。

https://blog.csdn.net/wwdwjm/article/details/77840113

主要是因為阿里雲的熵池太小 熵池的大小是根據鍵盤 鼠標之類的噪音產生的數 然后/dev/random會根據熵池來生成隨機數 而生成需要有足夠的熵池里的噪音數 如果沒有達到的話就會一直阻塞 tomcat啟動的時候為了生成session id就會獲取這個隨機數來生成密匙 所以才出現上面的情況 一直阻塞在等待熵池里的數滿足生成隨機數的大小 3分鍾以后熵池里的數夠大了才開始部署

yum install -y rng-tools
systemctl start rngd
cp /usr/lib/systemd/system/rngd.service /etc/systemd/system
vi /etc/systemd/system/rngd.service

ExecStart=/sbin/rngd -f -r /dev/urandom

WARNING: Creation of SecureRandom instance for session ID generation using [SHA1PRNG] took [348,853] milliseconds

后來查了一下,發現這個問題抱怨的還是蠻多的,以至於tomcat的wiki里面還單獨列出來作為加速啟動的一個方面:

Tomcat 7+ heavily relies on SecureRandom class to provide random values for its session ids and in other places. Depending on your JRE it can cause delays during startup if entropy source that is used to initialize SecureRandom is short of entropy. You will see warning in the logs when this happens, e.g.:

There is a way to configure JRE to use a non-blocking entropy source by setting the following system property: -Djava.security.egd=file:/dev/./urandom

嘗試使用-Djava.security.egd=file:/dev/./urandom啟動了一下,果然快了很多。

https://wiki.apache.org/tomcat/HowTo/FasterStartUp

Centos6

yum install rng-tools -y
cat /etc/sysconfig/rngd 

# Add extra options here
EXTRAOPTIONS="-r /dev/urandom"

service rngd start
cat /proc/sys/kernel/random/entropy_avail


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM