0
我認爲terracotta bigmemory可以很容易地解決數據一致性問題,但它需要ehcache.xml和源代碼中的幾個參數/屬性,因爲我在其文檔上閱讀它。Terracotta BigMemory共享數據不一致
我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>
和代碼段讀取,並增加對共享數據現在值:
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。
transactionController屬於緩存對象。據文件記載,開始和提交方法將保證原子性。和'是',一致性很強。 (見上面的.xml)@louis_jacomet – bAris
好的,你能指出你是如何得到它的?這可能意味着您正在嘗試使用本地事務而不配置它們。所以並不感到驚訝,它不能按預期工作。 –