1 22 package test.patterns.readwritelock; 23 import junit.framework.TestCase; 24 25 30 public class JUnitTestReadWriteLockAspects 31 extends TestCase 32 { 33 public JUnitTestReadWriteLockAspects(String arg0) { 34 super(arg0); 35 36 } 37 38 public static void testProcessReadWriteLockPattern() 39 { 40 41 Account accountWithoutReadWriteLock = new Account(1000); 42 processReadWriteLockPattern(accountWithoutReadWriteLock); 43 44 assertTrue("No Concurrent Issue without ReadWriteLock Aspect !",1000!=accountWithoutReadWriteLock.getBalance()); 45 Account accountWithReadWriteLock = new AccountWithReadWriteLock(1000); 46 processReadWriteLockPattern(accountWithReadWriteLock); 47 assertTrue("Concurrent Issue with ReadWriteLock Aspect !",1000==accountWithReadWriteLock.getBalance()); 48 49 } 50 51 public static void processReadWriteLockPattern(Account account) 52 { 53 54 new Thread (new ProcessTransaction(account,100)).start(); 55 new Thread (new ProcessTransaction(account,300)).start(); 56 new Thread (new ProcessTransaction(account,-150)).start(); 57 new Thread (new ProcessTransaction(account,-250)).start(); 58 59 try 60 { 61 Thread.sleep(500); 62 } 63 catch (Exception e) 64 { 65 System.out.println(e); 66 } 67 } 68 69 70 71 72 73 74 75 76 } | Popular Tags |