jQuery in Action, 3rd edition
The moose likes Threads and Synchronization and the fly likes thread safe for SecureRandom.nextBytes()? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Threads and Synchronization
Bookmark "thread safe for SecureRandom.nextBytes()?" Watch "thread safe for SecureRandom.nextBytes()?" New topic

thread safe for SecureRandom.nextBytes()?

david chan
Ranch Hand

Joined: Jun 10, 2002
Posts: 46
I have a servlet which will initialize a static SecureRandom object then it will be used in doPost method to get a random byte[] for each http request.
Is it thread safe for the nextBytes() method in this manner?
Cindy Glass
"The Hood"

Joined: Sep 29, 2000
Posts: 8521
Moving this to Threads.

"JavaRanch, where the deer and the Certified play" - David O'Meara
Jim Yingst

Joined: Jan 30, 2000
Posts: 18671
Looking at the source code, yes, the class appears to be thread safe. Unfortunately the authors did not bother to document this fact in the source. Also i didn't check the class thouroughly; it's possible some of the methods are not thread-safe. To be sure, you should really put in synchronization yourself I think. But you can probably get away without it if you want.

"I'm not back." - Bill Harding, Twister
I agree. Here's the link: http://aspose.com/file-tools
subject: thread safe for SecureRandom.nextBytes()?
It's not a secret anymore!