简体   繁体   中英

Ehcache transaction timeout using transaction controller

Ehcache.xml

<ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xsi:noNamespaceSchemaLocation="ehcache.xsd" maxBytesLocalHeap="800M">

        <diskStore path="java.io.tmpdir"/>
        <defaultCache eternal="true" overflowToOffHeap="false" overflowToDisk="false" transactionalMode="local"/>

    </ehcache>

I'm using TransactionController for my transaction management.

 final boolean isLocalTransactionContext = mTransactionManager.getCurrentTransactionContext() == null;
        try {
            if (isLocalTransactionContext) {
                mTransactionManager.begin(10);
            }

Element cacheElement = mCache.get(Key);
return cacheElement;
} finally {
            if (isLocalTransactionContext) {
                mTransactionManager.commit();
            }
        }

It runs into time out when object for "key" that i'm looking for in cache is not available there. Ideally it should simply return 'null' but it runs into timeout. As well this is not always reproducible error.

et.sf.ehcache.transaction.TransactionTimeoutException: transaction [41] timed out
     net.sf.ehcache.transaction.local.LocalTransactionStore.assertNotTimedOut(LocalTransactionStore.java:108)
     net.sf.ehcache.transaction.local.LocalTransactionStore.get(LocalTransactionStore.java:349)
     net.sf.ehcache.store.AbstractCopyingCacheStore.get(AbstractCopyingCacheStore.java:95)
     net.sf.ehcache.store.TxCopyingCacheStore.get(TxCopyingCacheStore.java:33)
     net.sf.ehcache.Cache.get(Cache.java:1723)
     net.sf.ehcache.Cache.get(Cache.java:1696)

What could be the problem here. Thanks in advance.

Since you're saying that this is not always reproducible, I assume that you get this exception from time to time and only after the configured transaction timeout (10 seconds in your sample) expired.

This can be, and probably is perfectly normal: if a concurrent transaction is modifying the element you're trying to get, your current transaction is going to block until after the other one commits or rolls back. Depending on the time that concurrent transaction takes, or if you have many transactions all contending on the same key, it is very well possible that one of them is eventually going to timeout.

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