This week's book giveaway is in the Performance forum.
We're giving away four copies of The Java Performance Companion and have Charlie Hunt, Monica Beckwith, Poonam Parhar, & Bengt Rutisson on-line!
See this thread for details.
Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

thread safe for SecureRandom.nextBytes()?

 
david chan
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
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?
Thanks.
David
 
Cindy Glass
"The Hood"
Sheriff
Posts: 8521
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Moving this to Threads.
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic