zoukankan      html  css  js  c++  java
  • SpringBoot系列: SpringBoot 启动慢的问题

    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

  • 相关阅读:
    代码块&继承&final关键字
    Java基础
    我的学习笔记
    CF743C 题解
    洛谷P4180 题解
    洛谷P3402 题解
    洛谷P3919 题解
    Noi.ac#30 题解
    Noi.ac #65题解
    Noi.ac #51题解
  • 原文地址:https://www.cnblogs.com/harrychinese/p/springboot_start_slow.html
Copyright © 2011-2022 走看看