Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Is java.security.MessageDigest methods digest() and reset() threadsafe

 
Chase Bonham
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are the java.security.MessageDigest methods digest() and reset() threadsafe?
 
Sam Semwal
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
MessageDigest probably isn't thread safe unless it's mentioned in the API.
 
Chase Bonham
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thats where the confusion is for me. In the Javadoc for the lang API, is it safe to assume that if nothing is mentioned about synchronization then it is probably thread safe??..

Look at .. java.text.SimpleDateFormat, java.util.HashMap there is specific
mention of synchronization.
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In general the rule is that you should assume that a class is not designed to be used by multiple threads, unless the docs specifically say it is. It's true that some docs specifically tell you when a class isn't thread-safe, but that's not really necessary. There are also a few classes which are really thread-safe even though the docs don't say so, but you generally can't rely on that. The default is that classes are not thread-safe unless it's otherwise stated.
 
Hongbing Kou
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Confirmed that it is not thread safe. You will get weird errors after loading up your application in multi-thread environment.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic