How to fix Tomcat 8 slow start issue

If you have installed Tomcat 8 on your Linux server and it is taking forever to (re)start, it is none of your faults. It happens when Java Runtime Environment (JRE) entropy source is short of entropy.

Tomcat 8+ relies on the SecureRandom class to provide randomly generated values for its session ids and other places. JRE can cause delays during startup if the entropy source used to initialize SecureRandom is short of entropy.

Note: If you are using Tomcat 9 with Java 11, just install Haveged by typing sudo apt install haveged in your terminal, and you're all good. There is no need to modify JDK security files. It might also work for Tomcat 8 with Java 8 (not tested and worked).

To fix the entropy issue, replace the blocking entropy source with a non-blocking source in the $JAVA_PATH/jre/lib/security/java.security file.

Depending on your installation of Java (headless JRE, Oracle Java, OpenJDK ...), $JAVA_PATH can be different. In my case (Java 8 OpenJDK on Ubuntu 18.04), it is /usr/lib/jvm/java-8-openjdk-amd64.

$ nano /usr/lib/jvm/java-8-openjdk-amd64/jre/lib/security/java.security

Find the line with securerandom.source=file:/dev/random text and change it to securerandom.source=file:/dev/./urandom. Save the file and restart Tomcat 8. That's it.

You can also fix this issue by setting the following system property that will configure the JRE to use a non-blocking entropy source.

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

✌️ Like this article? Follow me on Twitter and LinkedIn. You can also subscribe to RSS Feed.

You might also like...

Digital Ocean

The simplest cloud platform for developers & teams. Start with a $200 free credit.

Buy me a coffee ☕

If you enjoy reading my articles and want to help me out paying bills, please consider buying me a coffee ($5) or two ($10). I will be highly grateful to you ✌️

Enter the number of coffees below:

✨ Learn to build modern web applications using JavaScript and Spring Boot

I started this blog as a place to share everything I have learned in the last decade. I write about modern JavaScript, Node.js, Spring Boot, core Java, RESTful APIs, and all things web development.

The newsletter is sent every week and includes early access to clear, concise, and easy-to-follow tutorials, and other stuff I think you'd enjoy! No spam ever, unsubscribe at any time.