java - XA模式下Ehcache无法将数据溢出到磁盘(NotSerializedException)

标签 java spring transactions ehcache xa

我正在使用 Ehcache 试验 XA 事务。目前我正在使用 Spring 事务管理和 Bitronix 作为事务管理器。

我使用以下方法创建、配置和填充缓存:

@Transactional
public void createCache() {
    this.cacheConfiguration = new CacheConfiguration("MyCache", 5000).diskPersistent(false).eternal(false)
            .diskExpiryThreadIntervalSeconds(1).maxElementsInMemory(70).transactionalMode(TransactionalMode.XA);
    final Configuration config = new Configuration();
    config.setDefaultCacheConfiguration(this.cacheConfiguration);
    final DiskStoreConfiguration diskStoreConfiguration = new DiskStoreConfiguration();
    diskStoreConfiguration.setPath("cache");
    config.addDiskStore(diskStoreConfiguration);
    this.cacheManager = new CacheManager(config);
    this.cacheConfiguration.name("primaryCache");
    this.cache = new Cache(this.cacheConfiguration);
    this.cacheManager.addCache(this.cache);

    for (int i = 0; i < 100; i++) {
        final Integer value = Integer.valueOf(i);
        this.cache.put(new Element(value, value));
    }
}

一切工作正常,Ehcache 按预期工作,被逐出的元素数量超过 70。

现在,如果我将 diskPersistentfalse 更改为 true,那么当 Ehcache 尝试将某些元素复制到磁盘时它就不起作用存储,但以下异常(exception):

[primaryCache.data] ERROR n.s.e.s.c.f.DiskStorageFactory btm-gtrid=737072696E672D62746D0000012F9296448C00000000 - Disk Write of 0 failed (it will be evicted instead): 
java.io.NotSerializableException: net.sf.ehcache.transaction.ReadCommittedSoftLockImpl

这是预期的,因为将 Ehcache 切换到事务模式会使它用 SoftLock 替换 Integer 类型的原始值:

[main] DEBUG n.s.e.t.local.LocalTransactionStore ehcache-txid=0, btm-gtrid=737072696E672D62746D0000012F9296448C00000000 - put: cache [primaryCache] key [0] was not in, soft lock inserted

为了完整起见,使用 Atomikos 事务管理器时也会发生这种情况,并且在不使用 XA 模式时可以完美地工作。

问题是:有没有办法混合 XA 事务和磁盘溢出?

最佳答案

一切都应该按照您的预期工作,但您刚刚发现了一个错误,该错误完全阻止开源磁盘持久存储在任何事务模式下工作。

请在 Ehcache JIRA (https://jira.terracotta.org/jira/browse/EHC) 中报告问题,我们会尽快修复。

关于java - XA模式下Ehcache无法将数据溢出到磁盘(NotSerializedException),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5793324/

相关文章:

php - PDO/PHP/MySQL 中的性能 : transaction versus direct execution

c# - TransactionScope 的层次结构

java - 防止从 Git 存储库 pull 时需要 "add external jars"

java - 尝试在本地运行应用程序引擎项目时权限被拒绝

java - 如何解决循环依赖?

java - Tomcat 7 WAR 部署 - "jar not loaded"

mysql - 使用 MySQL,如何开始;回滚;并提交;与自动提交有关?

java - 加载 Java derby 驱动程序时出错?

java - 在 Selenium Webdriver java 中切换到其他浏览器窗口后无法单击链接

java - 如何在 Spring 测试中重用 ContextConfiguration 注释的位置值