Home / Java Patterns and Pitfalls     frequal.com

Preventing Random Hangs On Linux

If your Java application is hanging randomly on Linux, add this Java property on the command-line:
-Djava.security.egd=file:///dev/./urandom

Details

Java on Linux sometimes needs a random number. It reads from /dev/random to get a random number from the OS.

Unfortunately /dev/random is a strict random number generator that returns random numbers based on system events. If there isn't enough system activity, /dev/random blocks, causing your whole application to block!

The solution is to switch to /dev/urandom, which always returns a number immediately. The number may not be perfectly random but for most applications this isn't a concern. To instruct the JVM to use /dev/urandom, add this command-line parameter: -Djava.security.egd=file:///dev/./urandom


Last modified on 31 Aug 2013 by AO

Copyright © 2024 Andrew Oliver