Updating integer atomically over multiple JVMs
abhishek_agarwal Dec 19, 2014 9:04 AMDear friends,
To narrow down my requirement I need to increment the integer atomically for every key that I put on the cache, across multiple JVMS(we are using tomcat) and i am using Optimistic locking for this.
Ex->
Key1, Initial Value 0
A Thread on JVM1 reads the value as 0
A Thread on JVM2 also read the value as 0
JVM1's thread increments to 1
JVM2's thread also increments to 2
JVM1's thread tries to update to 2 for key Key1and is succesful
When JVM2's thread tries to update it 2 it should fail, so this thread will now be reading it again and then increment that.
What I am observing this failure is not always happening.
And its not just multiple JVMs, even when I am testing on a single JVM with multiple threads then also i am observing this issue.
My infinispan configuration with Infinispan 6 is as below. I tried with Infi
?xml version="1.0" encoding="UTF-8"?>
<infinispan
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="urn:infinispan:config:6.0 http://www.infinispan.org/schemas/infinispan-config-6.0.xsd"
xmlns="urn:infinispan:config:6.0">
<global>
<transport>
<properties>
<property name="configurationFile" value="jgroups-udp.xml"/>
</properties>
</transport>
</global>
<default>
<!-- Configure an asynchronous replication cache -->
<clustering mode="replication">
<sync/>
</clustering>
</default>
<namedCache name="samplingBucketsCache">
<transaction
transactionManagerLookupClass="org.infinispan.transaction.lookup.JBossStandaloneJTAManagerLookup"
transactionMode="TRANSACTIONAL"
lockingMode="OPTIMISTIC"
useSynchronization="true"
autoCommit="true"
syncRollbackPhase="false"
syncCommitPhase="false"
useEagerLocking="false"/>
<locking writeSkewCheck="true" useLockStriping="false" isolationLevel="REPEATABLE_READ" lockAcquisitionTimeout="3000" />
<versioning enabled="true" versioningScheme="SIMPLE" />
<!-- Use the configuration of the default cache as it is -->
</namedCache>
</infinispan>