Example #1
0
 public boolean equals(Object obj) {
   if (this == obj) return true;
   if (obj != null && obj.getClass() == Account.class) {
     Account target = (Account) obj;
     return target.getAccountNo().equals(accountNo);
   }
   return false;
 }
 @Override
 // Keep subtracting an amount from the account
 public void run() {
   while (true) {
     account.withdraw((int) (Math.random() * 10) + 1);
   }
 }
 @Override
 // Keep adding an amount to the account
 public void run() {
   try { // Purposely delay it to let the withdraw method proceed
     while (true) {
       account.deposit((int) (Math.random() * 10) + 1);
       Thread.sleep(1000);
     }
   } catch (InterruptedException ex) {
     ex.printStackTrace();
   }
 }