package com.itcast.band;
public class constants
{
public static int MAX_SERVERS_TIME = 10000; //10S
public static int MIN_SERVER_TIME = 1000; //1S
/*定义一个普通客户间隔时间:*/
public static int COMMON_CUSTOMER_INTERVAL_TIME = 1;
}
package com.itcast.band;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
public class MainClass
{
public static void main(String[] args)
{
/*产生普通服务窗口:*/
for(int i = 1;i<5;i++)
{
ServiceWindow commonWindow = new ServiceWindow();
commonWindow.setWindowId(i);
commonWindow.setType(CustomerTypes.COMMON);
commonWindow.start();
}
/*产生快速窗口*/
ServiceWindow expressWindow = new ServiceWindow();
//commonWindow.setType(EXPRESS); 总结: 应当注意的是我们应当如何获取这个对象,注意如何对于不属于一个类当中的成员属性和方法的调用,别忘了类名.xxx
expressWindow.setType(CustomerTypes.EXPRESS);
expressWindow.start();
/*产生VIP窗口*/
ServiceWindow VIPWindow = new ServiceWindow();
VIPWindow.setType(CustomerTypes.VIP);
VIPWindow.start();
/*接下来客户开始取号*/
Executors.newScheduledThreadPool(1).scheduleAtFixedRate(
new Runnable()
{
public void run()
{
Integer number = NumberMachine.getInstance().getCommonManager().generateNewManager();
System.out.println(number + "号普通客户正在等待服务!");
}
},
0,
constants.COMMON_CUSTOMER_INTERVAL_TIME,
TimeUnit.SECONDS);
Executors.newScheduledThreadPool(1).scheduleAtFixedRate(
new Runnable()
{
public void run()
{
Integer number = NumberMachine.getInstance().getVIPManager().generateNewManager();
System.out.println(number + "号VIP客户正在等待服务!");
}
},
0,
constants.COMMON_CUSTOMER_INTERVAL_TIME * 6,
TimeUnit.SECONDS);
Executors.newScheduledThreadPool(1).scheduleAtFixedRate(
new Runnable()
{
public void run()
{
Integer number = NumberMachine.getInstance().getExpressManager().generateNewManager();
System.out.println(number + "号快速客户正在等待服务!");
}
},
0,
constants.COMMON_CUSTOMER_INTERVAL_TIME * 2,
TimeUnit.SECONDS);
}
}
|
|