场景重现:
CentOS7.2
JDK1.7
Tomcat8
启动tomcat日志:
根据日志,在执行createSecureRandom时,消耗了328秒。
根据百度,tomcat7及以后的版本,依赖SecureRandom这个类为它的session id获取随机数,这会导致在tomcat启动时造成非常大的耗时。
解决办法:
可以通过配置JRE使用非阻塞的Entropy Source,在$JAVA_HOME/jre/ lib/security/java.security中修改以下内容:
#securerandom.source=file:/dev/urandom
securerandom.source=file:/dev/./urandom
再看tomcat 启动日志
根据日志,可以看到tomcat启动是跳过了createSecureRandom。
新的发现:
此种情况在CentOS6.8上不会发生。