0 Replies Latest reply on Nov 15, 2010 3:42 AM by jonasrodoni

    BUG?  java.lang.IllegalMonitorStateException

    jonasrodoni Newbie

      Hi!

       

      I have written a small test to do som performance tests between EhCache and Infinispan. I create a bunch of threads that do alot of put and gets to the cache..

       

      When I have few elements (~10) I get IllegalMonitorStateException:s in the put-threads..  If I increase the elements to 100, it works fine, so I guess the problem occurs when I try to get and put the same key at the same time..

       

      Have I configured it wrong somehow or is it a bug?  I'm running Infinispan 4.2.0.BETA1

       

      Below is the stacktrace and the test..

       

      BR

      Jonas

       

       

      Exception in thread "Thread-6" java.lang.IllegalMonitorStateException
      at java.util.concurrent.locks.ReentrantLock$Sync.tryRelease(ReentrantLock.java:127)
      at java.util.concurrent.locks.AbstractQueuedSynchronizer.release(AbstractQueuedSynchronizer.java:1175)
      at java.util.concurrent.locks.ReentrantLock.unlock(ReentrantLock.java:431)
      at org.infinispan.util.concurrent.locks.containers.AbstractStripedLockContainer.releaseLock(AbstractStripedLockContainer.java:97)
      at org.infinispan.util.concurrent.locks.LockManagerImpl.unlock(LockManagerImpl.java:100)
      at org.infinispan.interceptors.LockingInterceptor.cleanupLocks(LockingInterceptor.java:352)
      at org.infinispan.interceptors.LockingInterceptor.doAfterCall(LockingInterceptor.java:300)
      at org.infinispan.interceptors.LockingInterceptor.visitPutKeyValueCommand(LockingInterceptor.java:251)
      at org.infinispan.commands.write.PutKeyValueCommand.acceptVisitor(PutKeyValueCommand.java:76)
      at org.infinispan.interceptors.base.CommandInterceptor.invokeNextInterceptor(CommandInterceptor.java:118)
      at org.infinispan.interceptors.base.CommandInterceptor.handleDefault(CommandInterceptor.java:132)
      at org.infinispan.commands.AbstractVisitor.visitPutKeyValueCommand(AbstractVisitor.java:57)
      at org.infinispan.commands.write.PutKeyValueCommand.acceptVisitor(PutKeyValueCommand.java:76)
      at org.infinispan.interceptors.base.CommandInterceptor.invokeNextInterceptor(CommandInterceptor.java:118)
      at org.infinispan.interceptors.TxInterceptor.enlistWriteAndInvokeNext(TxInterceptor.java:172)
      at org.infinispan.interceptors.TxInterceptor.visitPutKeyValueCommand(TxInterceptor.java:120)
      at org.infinispan.commands.write.PutKeyValueCommand.acceptVisitor(PutKeyValueCommand.java:76)
      at org.infinispan.interceptors.base.CommandInterceptor.invokeNextInterceptor(CommandInterceptor.java:118)
      at org.infinispan.interceptors.InvocationContextInterceptor.handleAll(InvocationContextInterceptor.java:87)
      at org.infinispan.interceptors.InvocationContextInterceptor.handleDefault(InvocationContextInterceptor.java:58)
      at org.infinispan.commands.AbstractVisitor.visitPutKeyValueCommand(AbstractVisitor.java:57)
      at org.infinispan.commands.write.PutKeyValueCommand.acceptVisitor(PutKeyValueCommand.java:76)
      at org.infinispan.interceptors.InterceptorChain.invoke(InterceptorChain.java:273)
      at org.infinispan.CacheDelegate.put(CacheDelegate.java:444)
      at org.infinispan.CacheSupport.put(CacheSupport.java:28)
      at com.netent.infinispanpoc.InfinispanBugTest$PutTesterThread.run(InfinispanBugTest.java:69)

      Exception in thread "Thread-6" java.lang.IllegalMonitorStateException

      at java.util.concurrent.locks.ReentrantLock$Sync.tryRelease(ReentrantLock.java:127)

      at java.util.concurrent.locks.AbstractQueuedSynchronizer.release(AbstractQueuedSynchronizer.java:1175)

      at java.util.concurrent.locks.ReentrantLock.unlock(ReentrantLock.java:431)

      at org.infinispan.util.concurrent.locks.containers.AbstractStripedLockContainer.releaseLock(AbstractStripedLockContainer.java:97)

      at org.infinispan.util.concurrent.locks.LockManagerImpl.unlock(LockManagerImpl.java:100)

      at org.infinispan.interceptors.LockingInterceptor.cleanupLocks(LockingInterceptor.java:352)

      at org.infinispan.interceptors.LockingInterceptor.doAfterCall(LockingInterceptor.java:300)

      at org.infinispan.interceptors.LockingInterceptor.visitPutKeyValueCommand(LockingInterceptor.java:251)

      at org.infinispan.commands.write.PutKeyValueCommand.acceptVisitor(PutKeyValueCommand.java:76)

      at org.infinispan.interceptors.base.CommandInterceptor.invokeNextInterceptor(CommandInterceptor.java:118)

      at org.infinispan.interceptors.base.CommandInterceptor.handleDefault(CommandInterceptor.java:132)

      at org.infinispan.commands.AbstractVisitor.visitPutKeyValueCommand(AbstractVisitor.java:57)

      at org.infinispan.commands.write.PutKeyValueCommand.acceptVisitor(PutKeyValueCommand.java:76)

      at org.infinispan.interceptors.base.CommandInterceptor.invokeNextInterceptor(CommandInterceptor.java:118)

      at org.infinispan.interceptors.TxInterceptor.enlistWriteAndInvokeNext(TxInterceptor.java:172)

      at org.infinispan.interceptors.TxInterceptor.visitPutKeyValueCommand(TxInterceptor.java:120)

      at org.infinispan.commands.write.PutKeyValueCommand.acceptVisitor(PutKeyValueCommand.java:76)

      at org.infinispan.interceptors.base.CommandInterceptor.invokeNextInterceptor(CommandInterceptor.java:118)

      at org.infinispan.interceptors.InvocationContextInterceptor.handleAll(InvocationContextInterceptor.java:87)

      at org.infinispan.interceptors.InvocationContextInterceptor.handleDefault(InvocationContextInterceptor.java:58)

      at org.infinispan.commands.AbstractVisitor.visitPutKeyValueCommand(AbstractVisitor.java:57)

      at org.infinispan.commands.write.PutKeyValueCommand.acceptVisitor(PutKeyValueCommand.java:76)

      at org.infinispan.interceptors.InterceptorChain.invoke(InterceptorChain.java:273)

      at org.infinispan.CacheDelegate.put(CacheDelegate.java:444)

      at org.infinispan.CacheSupport.put(CacheSupport.java:28)

      at com.netent.infinispanpoc.InfinispanBugTest$PutTesterThread.run(InfinispanBugTest.java:69)

       

       

       

       

       

      import org.infinispan.Cache;

      import org.infinispan.eviction.EvictionStrategy;

      import org.infinispan.manager.DefaultCacheManager;

      import org.infinispan.manager.EmbeddedCacheManager;

      import org.junit.BeforeClass;

      import org.junit.Test;

       

      public class InfinispanBugTest {

      private static final int NUMBER_OF_THREADS = 10;

      private static final long RUN_TEST_FOR_SECONDS = 5;

      private static final int ELEMENTS_IN_CACHE = 10;

       

      private static Cache<Long, String> theInfinispanCache;

       

      @BeforeClass

      public static void init() {

      // Infinispan

      EmbeddedCacheManager infinispanManager = new DefaultCacheManager();

      org.infinispan.config.Configuration config = new org.infinispan.config.Configuration();

      // configure your config bean accordingly

      config.setEvictionStrategy(EvictionStrategy.LRU);

      config.setExpirationMaxIdle(20);

      config.setExpirationLifespan(20);

      config.setEvictionMaxEntries(ELEMENTS_IN_CACHE);

      infinispanManager

      .defineConfiguration("myCustomInfinispanCache", config);

      theInfinispanCache = infinispanManager

      .getCache("myCustomInfinispanCache");

       

      for (long keyCounter = 0; keyCounter < ELEMENTS_IN_CACHE; keyCounter++) {

      theInfinispanCache.put(keyCounter, "value");

      }

      }

       

      @Test

      public void runMixPerformanceTest() throws Exception {

      Thread[] threads = new Thread[NUMBER_OF_THREADS];

      int i = 0;

      while (i < NUMBER_OF_THREADS) {

      threads[i] = new GetTesterThread(theInfinispanCache);

      i++;

      threads[i] = new PutTesterThread(theInfinispanCache);

      threads[i].start();

      threads[i-1].start();

      i++;

      }

      for (i = 0; i < NUMBER_OF_THREADS; i++) {

      threads[i].join();

      }

      }

       

      class PutTesterThread extends BaseTesterThread {

       

      public PutTesterThread(Cache<Long, String> cache) {

      super(cache);

      }

       

      public void run() {

      // put

      long startTime = System.currentTimeMillis();

      long endTime = startTime + RUN_TEST_FOR_SECONDS * 1000;

      long counter = 0;

      long keyCounter = 0;

      while (System.currentTimeMillis() < endTime) {

      cache.put(keyCounter, "value");

      counter++;

      keyCounter++;

      if (keyCounter >= ELEMENTS_IN_CACHE) {

      keyCounter = 0;

      }

      }

      System.out.println(cache.getName() + ": ran put " + counter

      + " times.   "

      + (RUN_TEST_FOR_SECONDS * 10000000 / counter) + "ns/10put");

      }

      }

       

      class GetTesterThread extends BaseTesterThread {

      public GetTesterThread(Cache<Long, String> cache) {

      super(cache);

      }

       

      public void run() {

      // get

      long startTime = System.currentTimeMillis();

      long endTime = startTime + RUN_TEST_FOR_SECONDS * 1000;

      long counter = 0;

      long keyCounter = 0;

      while (System.currentTimeMillis() < endTime) {

      String value = cache.get(keyCounter);

      counter++;

      keyCounter++;

      if (keyCounter >= ELEMENTS_IN_CACHE) {

      keyCounter = 0;

      }

      }

      System.out.println(cache.getName() + ": ran get " + counter

      + " times.   "

      + (RUN_TEST_FOR_SECONDS * 10000000 / counter) + "ns/10get");

      }

      }

       

      class BaseTesterThread extends Thread {

      protected Cache<Long, String> cache;

       

      public BaseTesterThread(Cache<Long, String> cache) {

      this.cache = cache;

      }

       

      }

       

      }