1 22 package test.patterns.readwritelock; 23 27 public class Account 28 { 29 30 private float balance; 31 32 public Account(float balance) 33 { 34 this.balance=balance; 35 } 36 37 public void debit(float amount) 38 { 39 float currentBalance = balance; 40 process(amount); 41 this.balance = currentBalance-amount; 42 } 43 44 public void credit(float amount) 45 { 46 float currentBalance = balance; 47 process(amount); 48 this.balance = currentBalance+amount; 49 } 50 51 public String toString() 52 { 53 return new StringBuffer ("Balance: $").append(this.balance).toString(); 54 } 55 public float getBalance() 56 { 57 return balance; 58 } 59 60 public void process(float ll) 61 { 62 try { 63 64 Thread.currentThread().sleep((long)ll); 65 } 66 catch (Exception e) 67 { 68 System.out.println(e); 69 } 70 } 71 } 72 73 74 | Popular Tags |