Is nextInt of SecureRandom class thread safe?

Hi,

I'm creating a web application and in one of my classes I have the following global variable defined:

privatestaticfinal SecureRandom generator =new SecureRandom();

In one of public methods, I then call:

int index = generator.nextInt(possibleRandomLength);

I therefore need to make sure that the nextInt method of SecureRandom is thread safe due to the obvious multithreading that happens in web applications.

I've browsed the web and the general feeling is that it is, however, can anyone confirm? I'm using Java 1.4.2

Many thanks

Mike

[767 byte] By [MikeUKDevelopera] at [2007-11-26 13:21:58]
# 1
I would not rely on it if the Javadoc does not say it is. Just create a static access method that is synchronized or a wrapper class that holds an instance of SecureRandom with synchronized access chained to the methods you need.
sabre150a at 2007-7-7 17:52:18 > top of Java-index,Other Topics,Algorithms...
# 2

Thinking about it I don't see how it can be thread safe

1) because it holds state which will be read and written as two steps

2) because the actual class used can be specified on the command line and a third party implementation may not be thread safe even if the Sun version is.

I would wrap it.

sabre150a at 2007-7-7 17:52:18 > top of Java-index,Other Topics,Algorithms...
# 3
Thanks for your help. Much appreciated. I'll wrap it. :)
MikeUKDevelopera at 2007-7-7 17:52:18 > top of Java-index,Other Topics,Algorithms...