package com.evs.objava33.class14;
public class Clerk implements Runnable {
private Bank bank;
private Transaction transaction;
public Clerk(Bank bank) {
this.bank = bank;
}
public void run() {
while (true) {
while (isBusy() == false) {
try {
Thread.sleep(10);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
bank.doTransaction(transaction);
transaction = null;
}
}
public void doTransaction(Transaction transaction) {
while (isBusy()) {
try {
Thread.sleep(10);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
this.transaction = transaction;
}
public boolean isBusy() {
return transaction != null;
}
}
No comments:
Post a Comment