Tomcat starts very slowly

A problem occurred after installing jdk1.8 and tomcat on the server under Alibaba Cloud. There was no problem when running tomcat for the first time, and the tomcat homepage could be accessed normally, but after shutting down and restarting, I found that the tomcat homepage could not be displayed.

Find catalina.sh in Tomcat's bin directory, find JAVA_OPTS and add the following configuration afterwards:

-Djava.security.egd=file:/dev/urandom

After adding, the following is the
Insert picture description here
reason:
Tomcat 7, Tomcat 8, Tomcat 9 will call org.apache.catalina.util.SessionIdGeneratorBase.createSecureRandom to generate a string of secure random numbers when starting.

In Linux (CentOS) environment, random numbers can be generated from two special files, one is /dev/urandom and the other is /dev/random.

Their principle of generating random numbers is to use the entropy pool of the current system to calculate a fixed number of random bits, and then return these bits as a byte stream. Entropy pool is the environmental noise of the current system. Entropy refers to the degree of confusion of a system. System noise can be evaluated by many parameters, such as memory usage, file usage, and the number of different types of processes.

/dev/random will block the program when it cannot generate a new random number, and will not return until new random bytes are generated according to the entropy pool; and /dev/urandom will not (ublock), of course, the effect of the random number generated is not Great.

So we force Tomcat to use /dev/urandom instead of /dev/random to generate random numbers, and the speed will be greatly improved-from several minutes to only a few seconds.

Reference:
Quickly solve the problem of slow startup of Tomcat, super simple to
solve the problem of slow startup of Tomcat

Guess you like

Origin blog.csdn.net/qq_33697094/article/details/110536253