Running Java in Amazon AWS or other virtualized containers

Sometimes when you try to start your java application in a virtualized environment like Amazon AWS, Virtualbox, Azure or similar you might get unexpected pauses, during up to several minutes, until the application starts if you run on linux!

This while starting the application locally on your personal server starts instantly! What is the difference?

It might be due to a common problem where the standard source of random number generation in java on linux is the entropy pool “/dev/random”, which blocks while retrieving new random numbers if it has not been seeded recently!

And as virtualized environments are not as “random” as physical servers, this means that it does not get seeded as often, or it might be due to that so many instances are running on the server, all requesting random numbers which might lead to the random number “pool” getting exhausted!

Fortunately there is another source of random numbers in linux “/dev/urandom” which does not block if it has not been reseeded regularly!

It has often been characterized as being less secure than“/dev/random”, but recent research show that it is not the case!

I would recommend the article http://www.2uo.de/myths-about-urandom/ for an indepth review of the security of “/dev/urandom”. According to that article “/dev/urandom” is just as secure as “/dev/random”

To enable usage of the non blocking random number generator in java, you need to add the switch

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

when starting the java application! The extra “/./” is due to a “closed” bug in java (https://bugs.openjdk.java.net/browse/JDK-6202721)!