MessageDigest ArrayIndexOutOfBoundsException
I use MessageDigest
to calculate the md5 signature in my project, but during the performance test it throws an ArrayIndexOutOfBoundsException
.
I have found a few posts that suggest this is because MessageDigest
is a singleton and not thread safe. Does anyone know how I can get around this problem, o开发者_高级运维r if there is an equivalent MessageDigest
class that is thread safe?
somebody says that this is beacause
MessageDigest
is singleton
That would be your MessageDigest
object. Not the class itself. MessageDigest.getInstance()
always returns a new instance: see the Javadoc.
and not thread save.
Thread safe.
Now, anyone knows how to solve this problem
Don't share your MessageDigest instance among multiple threads. Don't even make it a class member, make it a local variable in the method(s) that call it.
精彩评论