简体   繁体   中英

EhCache Deadlock issue while using RMI Cache Replicator

I am facing the cache deadlock issue in my application while RMI Cache Replicator strategy. Following is the exception log:

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)

Following is my ehcache configuration with RMI synchronization:

<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>

I am using ehcache-core ver 2.4.3 . Appreciate any help.

This might not be the answer you are looking for, but RMI replication and transactional caches aren't supported together. Now, the reason for the DeadLock isn't necessarily the RMI replication though. You can read on the different transactional modes here: http://ehcache.org/documentation/apis/transactions But basically, other than in an xa_strict environment, you might get these. So if that's a price you're not willing to pay, you need to make sure all transactions manage to access an entry prior to timing out (ie having a long time out would solve your problem). The xa & local transaction caches will throw the exception if they can't "lock" the entry within that timeout period, because it's currently locked by another transaction/thread. Hope this makes sense.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM