tomcat7/8/9在linux环境下启动慢的优化办法

云服务器:阿里云CentOS7.3 64,Tomcat:9.0.14.0

tomcat webapps下的项目

tomcat启动耗时

现象:如上图所示,tomcat官网下载的压缩包,未做任何添加,启动耗时11分34秒

原因
Tomcat 7/8都使用org.apache.catalina.util.SessionIdGeneratorBase.createSecureRandom类产生安全随机类SecureRandom的实例作为会话ID,这里花去了342秒,也即接近6分钟。

解决办法

  • 1、在Tomcat环境中解决
    可以通过配置JRE使用非阻塞的Entropy Source。
    在catalina.sh中加入这么一行:-Djava.security.egd=file:/dev/./urandom 即可。

  • 2、在JVM环境中解决
    打开$JAVA_PATH/jre/lib/security/java.security这个文件,找到下面的内容:
    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

修改完后会有明显的改善效果

©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容