List of usage examples for javax.transaction RollbackException printStackTrace
public void printStackTrace()
From source file:edu.illinois.enforcemop.examples.jbosscache.PessimisticSyncReplTxTest.java
/** * Have both cache1 and cache2 do add and commit. cache1 commit should time * out since it can't obtain the lock when trying to replicate cache2. On the * other hand, cache2 commit will succeed since now that cache1 is rollbacked * and lock is released.//from w w w . jav a 2 s .co m */ public void testPutTx1() throws Exception { final CacheSPI<Object, Object> c1 = this.cache1; final Semaphore threadOneFirstPart = new Semaphore(0); final Semaphore threadTwoFirstPart = new Semaphore(0); final Semaphore threadOneSecondPart = new Semaphore(0); Thread t1 = new Thread() { public void run() { TransactionManager tm; try { tm = beginTransaction(); c1.put("/a/b/c", "age", 38); c1.put("/a/b/c", "age", 39); threadOneFirstPart.release(); threadTwoFirstPart.acquire(); try { tm.commit(); } catch (RollbackException ex) { } finally { threadOneSecondPart.release(); } } catch (Throwable ex) { ex.printStackTrace(); t1_ex = ex; } } }; Thread t2 = new Thread() { public void run() { TransactionManager tm; try { threadOneFirstPart.acquire(); tm = beginTransaction(); assertNull(cache2.get("/a/b/c", "age"));// must be null as not yet // committed cache2.put("/a/b/c", "age", 40); threadTwoFirstPart.release(); threadOneSecondPart.acquire(); assertEquals(40, cache2.get("/a/b/c", "age"));// must not be null tm.commit(); tm = beginTransaction(); assertEquals("After cache2 commit", 40, cache2.get("/a/b/c", "age")); tm.commit(); } catch (Throwable ex) { ex.printStackTrace(); t2_ex = ex; } finally { lock.release(); } } }; // Let the game start t1.start(); t2.start(); t1.join(); t2.join(); if (t1_ex != null) { fail("Thread1 failed: " + t1_ex); } if (t2_ex != null) { fail("Thread2 failed: " + t2_ex); } }