Random in Java

Just debugging some Java over the weekend and one thing that floated around was that using STRACE on various Java threads produced output that had the error:

EAGAIN (Resource temporarily unavailable)

Poking around there is a bug open with Sun about how Java produces random numbers on JDK 1.4. Looks like it reads in the /jre/lib/security/java.security file to determine which file on the operating system to get random numbers from. On Linux this is /dev/random. /dev/random has the possibility of becoming empty because it is essentially a list of random numbers produced by watching various system resources. The solution appears to be to change the value in the security file to use urandom instead. The changes would look like this:

securerandom.source=file:/dev/urandom

/dev/urandom is will use /dev/random unless it is empty in which case it will use a pseudo-random number algorithm. Here is the bug for it:


http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4705093

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s