簡體   English   中英

EHCache Local TransactionManager 刪除超時

[英]EHCache Local TransactionManager timeout on removal

我正在從事一個合並 ehCache 的項目。 目前我正在編寫 JUnit 測試來測試各種行為。 添加事務管理器時,我開始在某些調用上看到超時問題。

目前使用eHcache 2.10.5 但也試過2.8.4 以下是我的xml

    <cache name="ehCache_1"
       maxElementsInMemory="20"
       eternal="false"
       overflowToDisk="false"
       timeToLiveSeconds="50"
       timeToIdleSeconds="10"
       transactionalMode="local">

下面是我的 JUnit

@Test
public void testEHCacheIssue(){
    try{
        Ehcache ehCache_1 = ehCacheManager.getCache("ehCache_1");
        transactionManager = ehCacheManager.getTransactionController();
        transactionManager.setDefaultTransactionTimeout(15);

        transactionManager.begin();
        ehCache_1.put(new Element("1", new TestElementPerson(1, "firstName1", "lastName1","email1@test.com",1234)));
        transactionManager.commit();

        transactionManager.begin();
        ehCache_1.put(new Element("2", new TestElementPerson(2, "firstName3", "lastName3","email3@test.com",1234)));
        transactionManager.commit();

        transactionManager.begin();
        ehCache_1.get("1");
        transactionManager.commit();

        transactionManager.begin(); 
        ehCache_1.remove("1");//Timeout happens here
        transactionManager.commit();

    }catch(Exception ex){
        LOGGER.error("There was an exception", ex);
        Assert.fail();
    }
}

在刪除時拋出以下錯誤:

有一個例外

net.sf.ehcache.transaction.TransactionTimeoutException:事務 [3] 超時 at.net.sf.ehcache.transaction.local.LocalTransactionStore.assertNotTimedOut(LocalTransactionStore.java:108) at.net.sf.ehcache.transaction.local。 LocalTransactionStore.remove(LocalTransactionStore.java:391) at.net.sf.ehcache.store.AbstractCopyingCacheStore.remove(AbstractCopyingCacheStore.java:110) at.net.sf.ehcache.store.TxCopyingCacheStore.remove(TxCopyingCacheStore.java:33) at.net.sf.ehcache.Cache.removeInternal(Cache.java:2426) at.net.sf.ehcache.Cache.remove(Cache.java:2331) at.net.sf.ehcache.Cache.remove(Cache. java:2249) at.net.sf.ehcache.Cache.remove(Cache.java:2227)

我注意到,如果我做任何涉及在現有密鑰上放置或刪除的操作,我都會遇到此問題。 我知道事務管理器鎖定了開始和提交之間的鍵,並且事務管理器的線程有時會在並發環境中超時,但我不確定如果事務管理器對任何對象的鍵都持有鎖定,我將如何使用事務管理器嚴重的時期。

超時問題與沒有按照文檔中的要求為我們正在緩存的對象定義 hashCode/toString 有關。

https://www.ehcache.org/documentation/2.8/apis/transactions.html#requirements

添加 hashCode/toString 為我自己解決了這個問題。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM