Creation of SecureRandom is slow, even in java 8

10,396

Solution 1

Try using the following command while running

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

Solution 2

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.

Share:
10,396
Ashish Jain
Author by

Ashish Jain

Founder of snapcx.io retail web services portal. At snapCX, I am building portfolio of REST style API endpoints (JSON payloads) for retail online channels. Few of services are running in production right now are Shipping Tracking for USPS, UPS, DHL, FedEx Address Validation and Correction (USPS engine) for USA addresses. Sales Tax calculations (estimate tax, calculate tax for an order with multiple shipping buckets.)

Updated on June 21, 2022

Comments

  • Ashish Jain
    Ashish Jain almost 2 years

    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

  • A.W.
    A.W. over 5 years
    This works for me on Ubuntu 18, Spring boot and Java 8.