2014-04-22 99 views
2

我在应用程序中遇到缓存死锁问题,同时使用RMI缓存复制器策略。 以下是异常日志:EhCache使用RMI缓存复制器时发生死锁问题

net.sf.ehcache.transaction.DeadLockException: deadlock detected in cache [abcCache] on key [1] between current transaction [139003] and foreign transaction [138998] 

at net.sf.ehcache.transaction.local.LocalTransactionStore.put(LocalTransactionStore.java:200) 
at net.sf.ehcache.transaction.local.JtaLocalTransactionStore.put(JtaLocalTransactionStore.java:268) 
at net.sf.ehcache.Cache.putInternal(Cache.java:1434) 
at net.sf.ehcache.Cache.put(Cache.java:1367) 
at net.sf.ehcache.Cache.put(Cache.java:1339) 

以下是我的Ehcache配置与RMI同步:

<transactionManagerLookup 
    class="net.sf.ehcache.transaction.manager.DefaultTransactionManagerLookup" 
    properties="jndiName=java:comp/UserTransaction" propertySeparator=";"/> 

<cacheManagerPeerProviderFactory 
    class="net.sf.ehcache.distribution.RMICacheManagerPeerProviderFactory" 
    properties="peerDiscovery=automatic, multicastGroupAddress=x.x.x.x, multicastGroupPort=xxxx, timeToLive=32"/>          

<cacheManagerPeerListenerFactory 
    class="net.sf.ehcache.distribution.RMICacheManagerPeerListenerFactory" 
    properties="port=40001, socketTimeoutMillis=2000"/> 

<cache 
    name="abcCache" 
    maxElementsInMemory="100" 
    eternal="false" 
    overflowToDisk="false" 
    diskPersistent="false" 
    timeToIdleSeconds="0" 
    timeToLiveSeconds="86400" 
    memoryStoreEvictionPolicy="LRU" 
    transactionalMode="xa"> 
    <cacheEventListenerFactory 
     class="net.sf.ehcache.distribution.RMICacheReplicatorFactory" 
     properties="replicatePuts=true, replicateUpdates=true, replicateRemovals=true, replicateUpdatesViaCopy=false, replicateAsynchronously=true, asynchronousReplicationIntervalMillis=500"/> 
</cache> 

我使用ehcache-core ver 2.4.3。 感谢任何帮助。

回答

1

这可能不是您正在寻找的答案,但RMI复制和事务性缓存不支持在一起。现在,DeadLock的原因不一定是RMI复制。你可以在这里阅读不同的交易模式:http://ehcache.org/documentation/apis/transactions 但基本上,除了在xa_strict环境中,你可能会得到这些。因此,如果这是您不愿意支付的价格,则需要确保所有交易在超时之前设法访问条目(即,长时间停留可以解决您的问题)。 本地事务高速缓存将在该超时期限内无法“锁定”条目时抛出异常,因为它当前被另一个事务/线程锁定。希望这是有道理的。