java - SecureRandom 实例创建需要很长时间才能完成

标签 java ubuntu tomcat encryption

在调查为什么我的 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/

相关文章:

java - 无法反序列化不同类型子对象的列表

java - 如何一般地指定可序列化列表

linux - 为另一个分区/目录运行 apt-get?

java - Spring @Scheduled 任务运行两次

java - 添加了对调用 Javascript 函数到小程序的支持,现在从 Tomcat 获取 404 No Context

java - 如何使用 Runtime.exec 重定向 dmesg 的数据?

java - 计算与另一个纬度/经度点有米距离的纬度和经度

C++ Ubuntu在终止时不释放对锁定文件的锁定

ubuntu - Ubuntu 云服务器镜像的登录凭据

jsp - 无缓存媒体的 Tomcat 配置