前段时间阿里云服务器维护,迁移了部分区域服务器,也是在此之后发现 Tomcat 启动缓慢,最终确定是随机数发生器导致启动过程被阻塞。
查找原因
完成一次重启,并查看启动日志:默认位置,tomcat安装目录下: tomcat_home /logs/catalina.out 文件中
19:53:17.753 INFO [main] org.apache.catalina.startup.Catalina.start Server startup in 321259 ms
看到Tomcat启动花费了300+秒,五分多钟。
顺着日志时间看到两条相邻的日志,时间间隔将近四分钟
19:47:58.285 INFO [localhost-startStop-1] org.apache.jasper.servlet.TldScanner.scanJars At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time.
19:52:46.795 INFO [localhost-startStop-1] org.apache.catalina.util.SessionIdGeneratorBase.createSecureRandom Creation of SecureRandom instance for session ID generation using [SHA1PRNG] took [288,433] milliseconds.
第二条日志中的SecureRandom便是被阻塞的部分了
解决方案
参考了这这两篇文章,修改之后,Tomcat 启动速度恢复正常