在调查为什么我的 Ubuntu 15 上的 tomcat 8 服务器在启动时没有响应时,发现它花费了大量时间来尝试创建 SecureRandom 实例。为什么会出现这种情况以及如何解决?
May 19, 2016 2:48:22 PM org.apache.jasper.servlet.TldScanner scanJars
INFO: 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.
May 19, 2016 3:21:37 PM org.apache.catalina.util.SessionIdGeneratorBase createSecureRandom
!!! ----> INFO: Creation of SecureRandom instance for session ID generation using [SHA1PRNG] took [1,994,925] milliseconds.
May 19, 2016 3:21:37 PM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deployment of web application directory /var/lib/tomcat8/webapps/ROOT has finished in 1,995,782 ms
May 19, 2016 3:21:37 PM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["http-nio-8080"]
May 19, 2016 3:21:37 PM org.apache.catalina.startup.Catalina start
INFO: Server startup in 1995884 ms
最佳答案
根据 Javadoc
Depending on the implementation, the {@code generateSeed} and {@code nextBytes} methods may block as entropy is being gathered, for example, if they need to read from /dev/random on various Unix-like operating systems.
你能检查一下/dev/random是否不慢,可能是secureRandom正在使用NativePRNG(/dev/random)?
有关/dev/random 速度缓慢的原因的更多详细信息,请参阅 /dev/random Extremely Slow?
关于java - SecureRandom 实例创建需要很长时间才能完成,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37328121/