1 22 package test.patterns.readwritelock; 23 27 public class Driver 28 { 29 30 public static void main(String [] args) 31 { 32 33 Account accountWithoutReadWriteLock = new Account(1000); 34 processReadWriteLockPattern(accountWithoutReadWriteLock); 35 System.out.println("Balance should be $1000 !"); 36 System.out.println("Concurrent Read/Write without Aspect: $"+accountWithoutReadWriteLock.getBalance()); 37 38 Account accountWithReadWriteLock = new AccountWithReadWriteLock(1000); 39 processReadWriteLockPattern(accountWithReadWriteLock); 40 System.out.println("Concurrent Read/Write with Aspect: $"+accountWithReadWriteLock.getBalance()); 41 } 42 43 public static void processReadWriteLockPattern(Account account) 44 { 45 46 new Thread (new ProcessTransaction(account,100)).start(); 47 new Thread (new ProcessTransaction(account,300)).start(); 48 new Thread (new ProcessTransaction(account,-150)).start(); 49 new Thread (new ProcessTransaction(account,-250)).start(); 50 51 try 52 { 53 Thread.currentThread().sleep(500); 54 } 55 catch (Exception e){} 56 57 58 } 59 60 61 62 63 64 65 66 67 68 69 70 71 } 72 | Popular Tags |