开发者

MessageDigest ArrayIndexOutOfBoundsException

开发者 https://www.devze.com 2023-04-12 05:35 出处:网络
I use MessageDigest to calculate the md5 signature in my project, but during the performance test it throws an 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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号