我在项目中使用 MessageDigest
计算 md5 签名,但在性能测试期间它抛出 ArrayIndexOutOfBoundsException
。
我发现一些帖子表明这是因为 MessageDigest
是单例且不是线程安全的。有谁知道我如何解决这个问题,或者是否有一个等效的线程安全的 MessageDigest
类?
最佳答案
somebody says that this is beacause
MessageDigest
is singleton
那将是您的 MessageDigest
对象。不是类(class)本身。 MessageDigest.getInstance()
始终返回一个新实例:请参阅 Javadoc。
and not thread save.
线程安全。
Now, anyone knows how to solve this problem
不要在多个线程之间共享您的 MessageDigest 实例。甚至不要将其设为类成员,而将其设为调用它的方法中的局部变量。
关于java - MessageDigest ArrayIndexOutOfBoundsException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7701260/