-
Enhancement
-
Resolution: Won't Do
-
Major
-
None
-
14.0.0.Final
-
None
Create a utility method to deal with cache operations during a transaction
Pseudo code
void doInTx(Runnable runnable, int maxAttempts) {
TransactionManager tm = myCache.cache.getAdvancedCache().getTransactionManager();
boolean success = false;
int count = 0;
while (!success && count < maxAttempts) {
boolean rollbackCalled = false;
try {
tm.begin();
runnable.run();
} catch (Exception e) {
rollbackCalled = true;
tm.rollback();
} finally {
count++;
if (!rollbackCalled) {
tm.commit();
success = true;
}
}
}
if (!success) {
throw new IllegalStateException("cannot do the operation");
}
}