001package edu.pdx.cs410J.net;
002
003/**
004 * Synchronized methods ensure that the data in the balance is
005 * accessed correctly.
006 */
007public class SynchronizedBankAccount extends BankAccount {
008  private static int nextId = 1;
009  int id = nextId++;
010
011  public synchronized int getBalance() {
012    return super.getBalance();
013  }
014
015  public synchronized void setBalance(int balance) {
016    super.setBalance(balance);
017  } 
018
019  public synchronized void doTransaction(int trans) {
020    // Will not attempt to re-obtain lock
021    int balance = this.getBalance();
022    balance += trans;
023    this.setBalance(balance);
024  }
025}