Khi bật tomcat, từ khi chạy startup tới khi server hoàn tất online có thể lên tới 30s. Nếu kiểm tra log catalina.out có thể thấy ghi chú rõ thời gian khởi động cho từng tiến trình của tomcat
Ví dụ:
31-Mar-2020 08:30:51.102 WARNING [main] org.apache.catalina.core.StandardContext.setPath A context path must either be an empty string or sta rt with a '/' and do not end with a '/'. The path [bill-live2] does not meet these criteria and has been changed to [/bill-live2] 31-Mar-2020 08:30:51.114 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Server version: Apache Tomcat/8.5.3 31-Mar-2020 08:30:51.114 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Server built: Jun 9 2016 11:16:29 UTC 31-Mar-2020 08:30:51.114 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Server number: 8.5.3.0 31-Mar-2020 08:30:51.114 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log OS Name: Linux 31-Mar-2020 08:30:51.114 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log OS Version: 2.6.32-642.el6.x86_64 31-Mar-2020 08:30:51.114 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Architecture: amd64 31-Mar-2020 08:30:51.114 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Java Home: /home/java8/jre 31-Mar-2020 08:30:51.114 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log JVM Version: 1.8.0_101-b13 31-Mar-2020 08:30:51.115 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log JVM Vendor: Oracle Corporation 31-Mar-2020 08:30:51.115 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log CATALINA_BASE: /home/devopsvn.xyz/runtime /huybk.com-live2 31-Mar-2020 08:30:51.115 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log CATALINA_HOME: /home/devopsvn.xyz/runtime /huybk.com-live2 31-Mar-2020 08:30:51.115 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.util.logging.config. file=/home/devopsvn.xyz/runtime/huybk.com-live2/conf/logging.properties 31-Mar-2020 08:30:51.115 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.util.logging.manager =org.apache.juli.ClassLoaderLogManager 31-Mar-2020 08:30:51.115 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djdk.tls.ephemeralDHKeySiz e=2048 31-Mar-2020 08:30:51.115 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcatalina.base=/home/congt hanhtoan/runtime/huybk.com-live2 31-Mar-2020 08:30:51.115 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcatalina.home=/home/congt hanhtoan/runtime/huybk.com-live2 31-Mar-2020 08:30:51.116 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.io.tmpdir=/home/cong thanhtoan/runtime/huybk.com-live2/temp 31-Mar-2020 08:30:51.116 INFO [main] org.apache.catalina.core.AprLifecycleListener.lifecycleEvent The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: /usr/java/packages/lib/amd64:/usr/lib64:/ lib64:/lib:/usr/lib 31-Mar-2020 08:30:51.235 INFO [main] org.apache.coyote.AbstractProtocol.init Initializing ProtocolHandler ["http-nio-8587"] 31-Mar-2020 08:30:51.254 INFO [main] org.apache.tomcat.util.net.NioSelectorPool.getSharedSelector Using a shared selector for servlet write/r ead 31-Mar-2020 08:30:51.256 INFO [main] org.apache.catalina.startup.Catalina.load Initialization processed in 585 ms 31-Mar-2020 08:30:51.280 INFO [main] org.apache.catalina.core.StandardService.startInternal Starting service Catalina 31-Mar-2020 08:30:51.280 INFO [main] org.apache.catalina.core.StandardEngine.startInternal Starting Servlet Engine: Apache Tomcat/8.5.3 31-Mar-2020 08:30:51.280 INFO [main] org.apache.catalina.core.StandardEngine.startInternal Starting Servlet Engine: Apache Tomcat/8.5.3 31-Mar-2020 08:30:53.861 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. SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder". SLF4J: Defaulting to no-operation (NOP) logger implementation SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details. 31-Mar-2020 08:31:27.681 INFO [localhost-startStop-1] org.apache.catalina.util.SessionIdGeneratorBase.createSecureRandom Creation of SecureRandom instance for session ID generation using [SHA1PRNG] took [33,353] milliseconds. 31-Mar-2020 08:31:29.269 INFO [main] org.apache.coyote.AbstractProtocol.start Starting ProtocolHandler [http-nio-8587] 31-Mar-2020 08:31:29.278 INFO [main] org.apache.catalina.startup.Catalina.start Server startup in 38021 ms
Như trên, chúng ta có thể thấy tomcat start mất 38s, một con số quá lớn. Nhìn lên phía trên sẽ có tiến trình SessionIdGeneratorBase khởi động mất 33s
Để khắc phục tốc độ khởi động của SessionIdGeneratorBase tiến hành làm như sau
Vào thư mục $JAVA_HOME/jre/lib/security/java.security
Thêm vào cuối file java.security
securerandom.source=file:/dev/urandom
Từ nay sẽ khắc phục được tốc độ khởi động của SessionIdGeneratorBase