【问题标题】:Ehcache transaction timeout using transaction controller使用事务控制器的 Ehcache 事务超时
【发布时间】:2017-05-18 11:08:25
【问题描述】:

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>

我正在使用 TransactionController 进行事务管理。

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

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

当我在缓存中查找的“键”对象不可用时,它会超时。理想情况下,它应该简单地返回“null”,但它会超时。同样,这并不总是可重现的错误。

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)

这可能是什么问题。提前致谢。

【问题讨论】:

    标签: java transactions timeout ehcache


    【解决方案1】:

    由于您说这并不总是可重现的,因此我假设您不时遇到此异常,并且仅在配置的事务超时(示例中为 10 秒)到期之后。

    这可能,而且很可能是完全正常的:如果一个并发事务正在修改您要获取的元素,那么您当前的事务将阻塞,直到另一个事务提交或回滚之后。根据并发事务所花费的时间,或者如果您有许多事务都在同一个键上竞争,很可能其中一个事务最终会超时。

    【讨论】:

    • 嗨@LudovicOrban,也许你是对的,但即使我增加超时问题仍然存在,然后在增加超时后超时。有什么办法可以检查哪个事务锁定了 Ehcahe 中的资源或找出问题的根本原因。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-05-26
    • 2013-09-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多