Bankpublic class Bank extends Object
Fields Summary |
---|
public static final int | NO_ACCS | public static final int | INIT_BAL | private int | noTransacts | private int[] | account |
Constructors Summary |
---|
public Bank()
account = new int[ NO_ACCS ];
for( int i = 0; i < account.length; i++ )
{ account[i] = INIT_BAL;
}
noTransacts = 0;
currentState();
|
Methods Summary |
---|
public void | currentState() int bal = 0;
for( int i=0; i < account.length; i++ )
{ bal += account[i];
}
System.out.println( "Transactions:\t" + noTransacts +
"\tTotal balance:\t" + bal );
| public static void | main(java.lang.String[] args) Bank theBank = new Bank();
for( int i=0; i < NO_ACCS; i++ )
{ new TransactionGenerator( theBank, i ).start();
}
| public void | transfer(int amount, int from, int to) while( account[from] < amount )
{ try
{ Thread.sleep(5);
}
catch( InterruptedException e ) {}
}
account[from] -= amount;
/**/ Thread.yield();
account[to] += amount;
noTransacts += 1;
if( noTransacts%100 == 0 )
{ currentState();
}
|
|