agent.java
来自「Java程序设计技巧与开发实例附书源代码。」· Java 代码 · 共 61 行
JAVA
61 行
import java.util.Date;
public class Agent
extends Thread
{
private boolean running = false;
private Business business = null;
private int ID = -1;
private int numCustomers = 0;
public Agent(Business _business, int _ID)
{
business = _business;
ID = _ID;
}
public void start()
{
running = true;
super.start();
}
public void halt()
{
running = false;
}
public int getHandled()
{
return numCustomers;
}
private void releaseCustomer(Customer customer)
{
numCustomers++;
business.checkoutCustomer(numCustomers, customer.getWaitTime(new Date()));
}
public void run()
{
while (running)
{
try
{
sleep( (int) (Math.random() * Simulator.MAX_TELLER_BREAK) + 1000);
Customer customer = business.requestCustomerFor(ID);
if (customer != null)
{
sleep(customer.getDelayTime());
releaseCustomer(customer);
}
}
catch (InterruptedException ie)
{
System.out.println("Teller exception: " + ie);
}
}
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?