2 Replies Latest reply on Jun 16, 2005 12:45 PM by Brian Dueck

    ReadWriteLockWithUpgrade concurrency problem due to ThreadLo

    Brian Dueck Newbie

      Hi;

      I've encountered a concurrency problem related to construction of new ReadWriteLockWithUpgrade instances.

      The problem stems from the use of an instance level ThreadLocal variable on ReadWriteLockWithUpgrade. As you can see from the following stack trace, construction of a ThreadLocal instances causes a static synchronized method on ThreadLocal to be invoked (nextHashCode).

      "Thread-2" prio=5 tid=0x009ff298 nid=0xca4 runnable [32ff000..32ffd8c]
       at java.lang.ThreadLocal.nextHashCode(ThreadLocal.java:84)
       - waiting to lock <0x5008dfd8> (a java.lang.Class)
       at java.lang.ThreadLocal.<init>(ThreadLocal.java:62)
       at org.jboss.cache.lock.ReadWriteLockWithUpgrade.<init>(ReadWriteLockWithUpgrade.java:59)
       at org.jboss.cache.lock.LockStrategyRepeatableRead.<init>(LockStrategyRepeatableRead.java:27)
       at org.jboss.cache.lock.LockStrategyFactory.getLockStrategy(LockStrategyFactory.java:42)
       at org.jboss.cache.lock.IdentityLock.<init>(IdentityLock.java:74)
       at org.jboss.cache.Node.init(Node.java:116)
       at org.jboss.cache.Node.init(Node.java:112)
       at org.jboss.cache.Node.<init>(Node.java:92)
       at org.jboss.cache.Node.getOrCreateChild(Node.java:292)
       at org.jboss.cache.interceptors.LockInterceptor.lock(LockInterceptor.java:203)
       at org.jboss.cache.interceptors.LockInterceptor.invoke(LockInterceptor.java:152)
       at org.jboss.cache.interceptors.Interceptor.invoke(Interceptor.java:41)
       at org.jboss.cache.interceptors.UnlockInterceptor.invoke(UnlockInterceptor.java:35)
       at org.jboss.cache.TreeCache.invokeMethod(TreeCache.java:3120)
       at org.jboss.cache.TreeCache.put(TreeCache.java:1767)
       at org.jboss.cache.tests.perf.basic.ConcurrentCacheTest$PutSubTree.run(ConcurrentCacheTest.java:237)
       at EDU.oswego.cs.dl.util.concurrent.PooledExecutor$Worker.run(Unknown Source)
       at java.lang.Thread.run(Thread.java:534)


      I've prototyped a change to ReadWriteLockWithUpgrade that uses a ThreadLocalMap (see http://www.me.umn.edu/~shivane/blogs/cafefeed/2004/06/of-non-static-threadlocals-and-memory.html for my inspiration) and that seems to have resolved the concurrency problem.

      I'd be happy to share my prototype changes if you'd like.

      Brian.