Using a ThreadLocal<http://java.sun.com/j2se/1.5.0/docs/api/java/lang/ThreadLocal.html>may work too.
On Mon, Mar 3, 2008 at 6:27 PM, Hanson Char <[EMAIL PROTECTED]> wrote: > Yup, message digest is stateful and is not thread-safe and a new instance > needs to be instantiated for every execution. Definitely a bug if a message > digest instance is being used by multiple threads concurrently without > synchronization. > > Hanson > > > On Mon, Mar 3, 2008 at 3:54 PM, Miguel De Avila <[EMAIL PROTECTED]> > wrote: > > > We're using the java client library from Greg Whalin ( > > http://www.whalin.com/memcached/). > > > > When using the consistent hash (md5-based) under heavy load we're seeing > > ArrayIndexOutOfBoundsExceptions, > > > > java.lang.ArrayIndexOutOfBoundsException > > at java.lang.System.arraycopy(Native Method) > > at sun.security.provider.DigestBase.engineUpdate(DigestBase.java > > :102) > > at sun.security.provider.MD5.implDigest(MD5.java:100) > > at sun.security.provider.DigestBase.engineDigest(DigestBase.java > > :161) > > at sun.security.provider.DigestBase.engineDigest(DigestBase.java > > :140) > > at java.security.MessageDigest$Delegate.engineDigest( > > MessageDigest.java:531) > > at java.security.MessageDigest.digest(MessageDigest.java:309) > > at com.danga.MemCached.SockIOPool.md5HashingAlg(SockIOPool.java > > :522) > > at com.danga.MemCached.SockIOPool.getHash(SockIOPool.java:547) > > at com.danga.MemCached.SockIOPool.getBucket(SockIOPool.java:557) > > at com.danga.MemCached.SockIOPool.getSock(SockIOPool.java:918) > > at com.danga.MemCached.MemCachedClient.get(MemCachedClient.java > > :1266) > > > > Looks like the culprit is the static MessageDigest instance on line 140 > > of SockIOPool.java. > > The MessageDigest instance is statefull, and I don't see any indication > > that it is thread-safe. > > > > Has anyone else encountered this problem? > > > > My plan is to switch to a stateless FNV hashing implementation. > > > > Miguel > > > > >
