Ashish Jain
Ashish Jain

Reputation: 429

Creation of SecureRandom is slow, even in java 8

I searched on this problem. I got impression, it is resolved in java 8. But suddenly, I started getting this problem in my new VM, based of ubuntu 14.04.

2015-07-27 14:56:35.324 INFO 11809 --- [localhost-startStop-1] o.a.c.util.SessionIdGeneratorBase : Creation of SecureRandom instance for session ID generation using [SHA1PRNG] took [167,833] milliseconds.

And java version is

java -version java version "1.8.0_45" Java(TM) SE Runtime Environment (build 1.8.0_45-b14) Java HotSpot(TM) 64-Bit Server VM (build 25.45-b02, mixed mode)

Server is ubuntu 14.04.

Another thing is, i running this java process as spring boot application, which has embedded tomcat running.

Any ideas, what could be wrong? I even tried,

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

Upvotes: 7

Views: 12596

Answers (2)

Julius Delfino
Julius Delfino

Reputation: 1031

Try replacing embedded tomcat with undertow, by pasting the snippet below into your pom.xml:

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-web</artifactId>
    <exclusions>
        <exclusion>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-tomcat</artifactId>
        </exclusion>
    </exclusions>
</dependency>
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-undertow</artifactId>
    <version>2.1.0.RELEASE</version>
</dependency>

It works for me perfectly. SecureRandom issue is a tomcat issue which you can totally replace with another servlet container.

Upvotes: 1

KarthiG
KarthiG

Reputation: 607

Try using the following command while running

java -Djava.security.egd=file:/dev/./urandom -jar demo.jar

Upvotes: 18

Related Questions