SpringBoot 应用启动速度往往很快, 但在某些Linux 服务器上可能会很慢, 可能超过1分钟, 有时候甚至启动不起来.

下面过程耗时太长:
IdGeneratorBase: Creation of SecureRandom instance for session ID generation using [SHA1PRNG] took [140,108] milliseconds.


原因是SpringBoot在生成Session Id时候会使用 SecureRandom 这个jre工具类, 以生成足够安全的随机数. 最终会用到在Linux的 /dev/random 这个阻塞型数字生成器, 它的特点是使用鼠标和键盘以及磁盘信息来产生熵, 但对于Linux 服务器, 鼠标和键盘活动可能会很少, 就有可能阻塞整个SpringBoot启动.


解决办法是, 替换 /dev/random 为 /dev/./urandom. 具体为:

方法一: 适合外置tomcat:
在tomcat 的 catalina.sh 中增加下面的 JAVA_OPTS:
-Djava.security.egd=file:/dev/./urandom

方法二: 适合外置或内置tomcat:
修改 $JAVA_PATH/jre/lib/security/java.security 文件,
将 securerandom.source=file:/dev/random 替换为下面一行:
securerandom.source=file:/dev/./urandom

相关文章:

  • 2021-04-02
  • 2022-01-15
  • 2021-06-03
  • 2022-12-23
  • 2022-12-23
  • 2021-12-22
  • 2021-05-09
  • 2022-12-23
猜你喜欢
  • 2021-09-19
  • 2022-01-02
  • 2021-05-02
  • 2021-10-29
  • 2022-01-10
  • 2022-01-18
  • 2021-12-09
相关资源
相似解决方案