【发布时间】:2016-08-19 00:06:17
【问题描述】:
我认为 terracotta bigmemory 可以轻松解决数据一致性问题,但它需要 ehcache.xml 和源代码中的多个参数/属性,正如我在其文档中阅读的那样。
我的 ehcache.xml 是:
<ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://ehcache.org/ehcache.xsd"
name="config">
<cache name="bigMemory"
maxBytesLocalHeap="128M"
copyOnRead="true"
copyOnWrite="true"
eternal="true">
<terracotta consistency="strong" />
</cache>
<terracottaConfig url="localhost:9510" rejoin="false"/>
</ehcache>
读取和递增共享数据现有值的代码sn-p是:
for (int i = 0; i < 1000; i++) {
transactionController.begin();
bigMemoryChip.put(new Element(uid, ((Long) bigMemoryChip.get(uid).getObjectValue())+1));
transactionController.commit();
}
我所做的是执行代码两次并观察它如何处理一致性,通常我期望最终值比初始值多 2000。
虽然我试了大约15次,只有一次比初始值多2000,但其他的都比初始值多1500-1700左右。
【问题讨论】:
标签: java shared-memory terracotta ehcache-bigmemory