云服務(wù)器:阿里云CentOS7.3 64,Tomcat:9.0.14.0

tomcat webapps下的項目

tomcat啟動耗時
現(xiàn)象:如上圖所示,tomcat官網(wǎng)下載的壓縮包,未做任何添加,啟動耗時11分34秒
原因
Tomcat 7/8都使用org.apache.catalina.util.SessionIdGeneratorBase.createSecureRandom類產(chǎn)生安全隨機類SecureRandom的實例作為會話ID,這里花去了342秒,也即接近6分鐘。
解決辦法
1、在Tomcat環(huán)境中解決
可以通過配置JRE使用非阻塞的Entropy Source。
在catalina.sh中加入這么一行:-Djava.security.egd=file:/dev/./urandom 即可。2、在JVM環(huán)境中解決
打開$JAVA_PATH/jre/lib/security/java.security這個文件,找到下面的內(nèi)容:
securerandom.source=file:/dev/random
替換成
securerandom.source=file:/dev/./urandom
[root@sihan ~]# vim /usr/lib/jvm/jdk1.8.0_202/jre/lib/security/java.security
# Specifying this System property will override the
# "securerandom.source" Security property.
#
# In addition, if "file:/dev/random" or "file:/dev/urandom" is
# specified, the "NativePRNG" implementation will be more preferred than
# SHA1PRNG in the Sun provider.
#
securerandom.source=file:/dev/./urandom
修改前啟動耗時

修改后啟動耗時

image.png
修改完后會有明顯的改善效果