我如何解决这个明显的EhCache死锁?

时间:2011-11-07 17:26:43

标签: java deadlock ehcache

使用ehCache 2.4.4,我似乎陷入了ehCache Segment对象的死锁。从其他日志记录中,我知道'等待线程',1694最后在生成此堆栈跟踪之前9小时运行。与此同时,1696年已经完成了许多其他的工作,所以这个锁定肯定会被错误地控制。

我非常有信心我没有直接直接锁定任何Segment实例,所以我认为这是库内部的某种问题。有什么想法吗?

"Model Executor - 1696" Id=1696 in TIMED_WAITING on lock=java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject@92eb1ed
at sun.misc.Unsafe.park(Native Method)
at java.util.concurrent.locks.LockSupport.parkNanos(Unknown Source)
at java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.awaitNanos(Unknown Source)
at java.util.concurrent.PriorityBlockingQueue.poll(Unknown Source)
at com.rtrms.application.modeling.local.BlockingTaskList.takeTask(BlockingTaskList.java:20)
at com.rtrms.application.modeling.local.ModelExecutor.executeNextTask(ModelExecutor.java:71)
at com.rtrms.application.modeling.local.ModelExecutor.run(ModelExecutor.java:46)

Locked synchronizers: count = 1
  - java.util.concurrent.locks.ReentrantReadWriteLock$NonfairSync@4a3d767f

"Model Executor - 1694" Id=1694 in WAITING on    lock=java.util.concurrent.locks.ReentrantReadWriteLock$NonfairSync@4a3d767f
 owned by Model Executor - 1696 Id=1696
at sun.misc.Unsafe.park(Native Method)
at java.util.concurrent.locks.LockSupport.park(Unknown Source)
at java.util.concurrent.locks.AbstractQueuedSynchronizer.parkAndCheckInterrupt(Unknown Source)
at java.util.concurrent.locks.AbstractQueuedSynchronizer.doAcquireShared(Unknown Source)
at java.util.concurrent.locks.AbstractQueuedSynchronizer.acquireShared(Unknown Source)
at java.util.concurrent.locks.ReentrantReadWriteLock$ReadLock.lock(Unknown Source)
at net.sf.ehcache.store.compound.Segment.unretrievedGet(Segment.java:248)
at net.sf.ehcache.store.compound.CompoundStore.unretrievedGet(CompoundStore.java:191)
at net.sf.ehcache.store.compound.impl.DiskPersistentStore.containsKeyInMemory(DiskPersistentStore.java:72)
at net.sf.ehcache.Cache.searchInStoreWithStats(Cache.java:1884)
at net.sf.ehcache.Cache.get(Cache.java:1549)
at com.rtrms.amoeba.cache.DistributedModeledSecurities.get(DistributedModeledSecurities.java:57)
at com.rtrms.amoeba.modeling.AssertPersistedModeledSecurities.get(AssertPersistedModeledSecurities.java:44)
at com.rtrms.application.modeling.tasks.ExpandableModelingTask.getNextUnexecutedTask(ExpandableModelingTask.java:35)
at com.rtrms.application.modeling.local.BlockingTaskList.takeTask(BlockingTaskList.java:36)
at com.rtrms.application.modeling.local.ModelExecutor.executeNextTask(ModelExecutor.java:71)
at com.rtrms.application.modeling.local.ModelExecutor.run(ModelExecutor.java:46)

Locked synchronizers: count = 0   

1 个答案:

答案 0 :(得分:1)

事实证明,像Cache.acquireWriteLockOnKey这样的调用最终会在内部Segment上获得锁定,所以这个明显的死锁是由一个不在finally块中的.unlock调用引起的。

编辑评论:这也意味着你可以争取试图锁定恰好位于同一段中的两个不同的密钥,这是非常不幸的。