Java Reference
In-Depth Information
an account
boolean done = false;
for(int i = 1 ; i <= maxTrans ; ++i) {
// Generate a random account index for operation
select = rand.nextInt(accounts.size());
amount = 50 + rand.nextInt(26);
// Generate amount
$50 to $75
transaction = new Transaction(accounts.get(select), // Account
type,
//
Transaction type
amount);
// of
amount
totals[select] += amount;
// Keep
total tally for account
done = false;
while(true) {
// Find a clerk to do the transaction
for(Clerk clerk : clerks) {
if(done = clerk.doTransaction(transaction))
break;
}
if(done) {
break;
}
// No clerk was free so wait a while
try {
Thread.sleep(10);
} catch(InterruptedException e) {
System.out.println(" TransactionSource\n" + e);
return totals;
}
}
if(Thread.interrupted()) {
System.out.println("Interrupt flag for "+ type +
" transaction source set.
Terminating.");
return totals;
}
}
return totals;
}
private TransactionType type;
private int maxTrans;
private Vector<Account> accounts;
private Vector<Clerk> clerks;
private int[] totals;
}
Directory "UsingExecutors"
Search WWH ::




Custom Search