黑马程序员技术交流社区
标题:
银行调度有点小问题
[打印本页]
作者:
乖睡觉咯
时间:
2013-8-23 22:15
标题:
银行调度有点小问题
package com.bank;
import java.util.Random;
import java.util.concurrent.Executors;
public class ServiceWindow {
private CustomerType type = CustomerType.COMMON;//定义客服类型,
public void setType(CustomerType type) { //定义set方法进行赋值、
this.type = type;
}
public void setWindowId(int windowId) {//定义set方法进行赋值、
this.windowId = windowId;
}
private int windowId = 1; //定义窗口
public void start(){
Executors.newSingleThreadExecutor().execute(new Runnable(){
public void run(){
while(true){
switch(type){
case COMMON:
commonService();
break;
case EXPRESS:
expressService();
break;
case VIP:
VipService();
break;
}
}
}
});
}
private void commonService() {
String windowName = "第"+windowId +"号"+type +"窗口";
int maxRand = Constants.MAX_SERVICE_TIME - Constants.MIN_SERVICE_TIME;
long serverTime = new Random().nextInt(maxRand)+1+Constants.MIN_SERVICE_TIME;
// 返回这个对象, 调用这个方法 在从号码机器上获取号码
Integer number = NumberMachine.getInstance().getCommonManager().fetchServiceNumber();
System.out.println(windowName+"正在获取任务");
if(number !=null){
System.out.println(windowName +"为第"+number+"号"+"普通" +"客服服务");
long beginTime = System.currentTimeMillis();
try {
Thread.sleep(serverTime);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
long costTime = System.currentTimeMillis()-beginTime;
System.out.println(windowName +"为第"+number+"号"+"普通" +
"客服服务完成,耗时"+costTime/1000+"秒");
}else{
System.out.println(windowName+"没有获取到任务,休息一秒。");
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
private void expressService() {
String windowName = "第"+windowId +"号"+type +"窗口";
//int maxRand = Constants.MAX_SERVICE_TIME - Constants.MIN_SERVICE_TIME;
//long serverTime = new Random().nextInt(maxRand)+1+Constants.MIN_SERVICE_TIME;
Integer number = NumberMachine.getInstance().getExpressManager().fetchServiceNumber();
System.out.println(windowName+"正在获取任务");
if(number !=null){
System.out.println(windowName +"为第"+number+"号"+type +"客服服务");
long beginTime = System.currentTimeMillis();
try {
Thread.sleep(Constants.MIN_SERVICE_TIME);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
long costTime = System.currentTimeMillis()-beginTime;
System.out.println(windowName +"为第"+number+"号"+type +
"客服服务完成,耗时"+costTime/1000+"秒");
}else{
System.out.println(windowName+"没有获取到任务");
expressService();
}
}
private void VipService() {
String windowName = "第"+windowId +"号"+type +"窗口";
int maxRand = Constants.MAX_SERVICE_TIME - Constants.MIN_SERVICE_TIME;
long serverTime = new Random().nextInt(maxRand)+1+Constants.MIN_SERVICE_TIME;
Integer number = NumberMachine.getInstance().getVipManager().fetchServiceNumber();
System.out.println(windowName+"正在获取任务");
if(number !=null){
System.out.println(windowName +"为第"+number+"号"+type +"客服服务");
long beginTime = System.currentTimeMillis();
try {
Thread.sleep(serverTime);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
long costTime = System.currentTimeMillis()-beginTime;
System.out.println(windowName +"为第"+number+"号"+type +
"客服服务完成,耗时"+costTime/1000+"秒");
}else{
System.out.println("没有获取到任务。");
commonService();
expressService();
}
}
}
复制代码
打印结果没有看见快速窗口为快速客服服务,vip也不为普通窗口服务。 求解决
作者:
以防万一
时间:
2013-8-30 00:32
{:soso_e176:}
亲,请问下问题是否解决?
如果已解决请及时将未解决改为已解决
如果未解决请回帖追问
三天未回复的将视为已解决
详情参考:
如何更改分类
保持队形,谢谢合作
{:soso_e181:}
欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/)
黑马程序员IT技术论坛 X3.2