tel1ersDoi ngOtherThi ngs.offer(tel1er);
}
public void runO { try {
while(!Thread.interruptedO) {
TimeUnit.MILLISECONDS.sleep(adjustmentPeriod);
adjustTellerNumberO;
System.out.print(customers +"{");
for(Teller teller ■ workingTellers)
System.out.print(teller.shortString() + " "); System.out.printIn("}");
} catchdnterruptedException е) {
System.out.printin(this + "прерван");
}
System.out println(this + "завершается");
}
public String toStringO { return "TellerManager "; }
}
public class BankTellerSimulation {
static final int MAX_LINE_SIZE = 50;
static final int ADJUSTMENT_PERIOD = 1000;
public static void main(String[] args) throws exception {
ExecutorService exec = Executors.newCachedThreadPoolО; // Если очередь слишком длинна, клиенты уходят: CustomerLine customers =
new CustomerLi ne(MAX_LINE_SIZE); exec.execute(new CustomerGenerator(customers)); // TellerManager добавляет и убирает кассиров // по мере необходимости: exec.execute(new TellerManager(
exec, customers. ADJUSTMENT_PERIOD)); if(args.length > 0) // Необязательный аргумент
Ti meUni t.SECONDS.s1eep(new Integer(args[0])).
else {
System.out.printIn("Press 'Enter' to quit"); System.in.readО;
}
exec.shutdownNowO;
}
} /* Output: