Dirty read even though configured as REPEATABLE_READ or READ
vishwasoft Jun 19, 2009 6:09 PMI'm trying to evaluate the JBossCache for our application
I'm getting dirty read even though I rollback transaction. I tried this with EJB3 Stateless session bean BMT.
Could you please anyone help me on this problem, Am I making anything wrong? please let me know if you need additional info
JBosscache : jbosscache-core-3.1.0.GA
JBoss As: jboss-5.0.0.GA
JDK: 1.5.0_07
Here is the code
public class TestEntity { private int array[] = new int[100000]; public void update(int value) { for (int i = 0; i < array.length; i++) { array [ i ]=value; } } public int[] getArray() { return array; } }
Stateless Bean1 code to modify cache
Stateless Bean 1
public void updateArray(int value) { TransactionManager tm = cache.getConfiguration().getRuntimeConfig().getTransactionManager(); try { tm.begin(); String key = node.getFqn().toString(); TestEntity t = (TestEntity) node.get(key); if(t != null) { t.update(value); node.put(key, t); } tm.rollback(); } catch (Exception e) { try { tm.rollback(); }catch(Exception ex1) { ex1.printStackTrace(); } e.printStackTrace(); } }
Stateless Bean 2 to read and validating array
public boolean validateArray() { TransactionManager tm = cache.getConfiguration().getRuntimeConfig().getTransactionManager(); try { tm.begin(); int a[] = readArray(); int value = a[0]; for (int i = 0; i < a.length; i++) { if(a != value) { System.out.println(a+":"+value); sctx.getUserTransaction().rollback(); return false; } } tm.commit(); }catch(Exception ex) { try { tm.rollback(); }catch(Exception ex1) { ex1.printStackTrace(); } ex.printStackTrace(); } return true; }
Configuration file:
I have used configuration file example for cache configuration
<locking isolationLevel="REPEATABLE_READ" lockParentForChildInsertRemove="false" lockAcquisitionTimeout="50000" nodeLockingScheme="mvcc" writeSkewCheck="true" concurrencyLevel="500" useLockStriping="false" /> <transaction transactionManagerLookupClass="org.jboss.cache.transaction.DummyTransactionManagerLookup" syncRollbackPhase="true" syncCommitPhase="true" /> <?xml version="1.0" encoding="UTF-8"?> <jbosscache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="urn:jboss:jbosscache-core:config:3.1"> <locking isolationLevel="REPEATABLE_READ" lockParentForChildInsertRemove="false" lockAcquisitionTimeout="50000" nodeLockingScheme="mvcc" writeSkewCheck="true" concurrencyLevel="500" useLockStriping="false" /> <transaction transactionManagerLookupClass="org.jboss.cache.transaction.DummyTransactionManagerLookup" syncRollbackPhase="true" syncCommitPhase="true" /> <jmxStatistics enabled="true" /> <shutdown hookBehavior="REGISTER" /> <listeners asyncPoolSize="1" asyncQueueSize="1000000" /> <serialization objectInputStreamPoolSize="50" objectOutputStreamPoolSize="50" version="3.0.0" marshallerClass="org.jboss.cache.marshall.VersionAwareMarshaller" useLazyDeserialization="false" useRegionBasedMarshalling="false" /> <loaders passivation="true" shared="false"> <preload> <node fqn="/" /> </preload> <loader class="org.jboss.cache.loader.bdbje.BdbjeCacheLoader" async="false" fetchPersistentState="true" ignoreModifications="false" purgeOnStartup="false"> <properties>location=c:/JavaTools/tmp</properties> </loader> </loaders> </jbosscache>