A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

© 乖睡觉咯 中级黑马   /  2013-8-23 22:15  /  881 人查看  /  1 人回复  /   0 人收藏 转载请遵从CC协议 禁止商业使用本文

  1. package com.bank;

  2. import java.util.Random;
  3. import java.util.concurrent.Executors;

  4. public class ServiceWindow {
  5.          private CustomerType type = CustomerType.COMMON;//定义客服类型,
  6.          public void setType(CustomerType type) {  //定义set方法进行赋值、
  7.                 this.type = type;
  8.         }
  9.         public void setWindowId(int windowId) {//定义set方法进行赋值、
  10.                 this.windowId = windowId;
  11.         }
  12.         private int windowId = 1; //定义窗口
  13.     public void start(){
  14.                    Executors.newSingleThreadExecutor().execute(new Runnable(){
  15.                          public void run(){
  16.                                  while(true){
  17.                                          switch(type){
  18.                                                  case COMMON:
  19.                                                 commonService();
  20.                                                          break;
  21.                                                  case EXPRESS:
  22.                                                          expressService();
  23.                                                          break;
  24.                                                  case VIP:
  25.                                                          VipService();
  26.                                                          break;
  27.                                          }
  28.                                  }                         
  29.                          }
  30.                    });
  31.     }
  32.                         private void commonService() {
  33.                                 String windowName = "第"+windowId +"号"+type +"窗口";
  34.                                 int maxRand  = Constants.MAX_SERVICE_TIME - Constants.MIN_SERVICE_TIME;                       
  35.                                 long serverTime = new Random().nextInt(maxRand)+1+Constants.MIN_SERVICE_TIME;
  36.                                                         //                 返回这个对象,     调用这个方法                              在从号码机器上获取号码
  37.                                 Integer number = NumberMachine.getInstance().getCommonManager().fetchServiceNumber();
  38.                                 System.out.println(windowName+"正在获取任务");
  39.                                 if(number !=null){
  40.                                         System.out.println(windowName +"为第"+number+"号"+"普通" +"客服服务");
  41.                                         long beginTime = System.currentTimeMillis();
  42.                                         try {
  43.                                                 Thread.sleep(serverTime);
  44.                                         } catch (InterruptedException e) {
  45.                                                 // TODO Auto-generated catch block
  46.                                                 e.printStackTrace();
  47.                                         }
  48.                                         long costTime = System.currentTimeMillis()-beginTime;
  49.                                         System.out.println(windowName +"为第"+number+"号"+"普通" +
  50.                                                         "客服服务完成,耗时"+costTime/1000+"秒");
  51.                                        
  52.                                 }else{
  53.                                         System.out.println(windowName+"没有获取到任务,休息一秒。");
  54.                                         try {
  55.                                                 Thread.sleep(1000);
  56.                                         } catch (InterruptedException e) {
  57.                                                 // TODO Auto-generated catch block
  58.                                                 e.printStackTrace();
  59.                                         }                                                                
  60.                                        
  61.                                 }
  62.                         }
  63.                         private void expressService() {
  64.                                 String windowName = "第"+windowId +"号"+type +"窗口";
  65.                                 //int maxRand  = Constants.MAX_SERVICE_TIME - Constants.MIN_SERVICE_TIME;                       
  66.                                  //long serverTime = new Random().nextInt(maxRand)+1+Constants.MIN_SERVICE_TIME;
  67.                                
  68.                                 Integer number = NumberMachine.getInstance().getExpressManager().fetchServiceNumber();
  69.                                 System.out.println(windowName+"正在获取任务");
  70.                                 if(number !=null){
  71.                                         System.out.println(windowName +"为第"+number+"号"+type +"客服服务");
  72.                                         long beginTime = System.currentTimeMillis();
  73.                                         try {
  74.                                                 Thread.sleep(Constants.MIN_SERVICE_TIME);
  75.                                         } catch (InterruptedException e) {
  76.                                                 // TODO Auto-generated catch block
  77.                                                 e.printStackTrace();
  78.                                         }
  79.                                         long costTime = System.currentTimeMillis()-beginTime;
  80.                                         System.out.println(windowName +"为第"+number+"号"+type +
  81.                                                         "客服服务完成,耗时"+costTime/1000+"秒");
  82.                                        
  83.                                 }else{
  84.                                         System.out.println(windowName+"没有获取到任务");
  85.                                         expressService();                                                        
  86.                                        
  87.                                 }
  88.                         }

  89.                         private void VipService() {
  90.                                 String windowName = "第"+windowId +"号"+type +"窗口";
  91.                                 int maxRand  = Constants.MAX_SERVICE_TIME - Constants.MIN_SERVICE_TIME;                       
  92.                                 long serverTime = new Random().nextInt(maxRand)+1+Constants.MIN_SERVICE_TIME;
  93.                                
  94.                                
  95.                                 Integer number = NumberMachine.getInstance().getVipManager().fetchServiceNumber();
  96.                                 System.out.println(windowName+"正在获取任务");
  97.                                 if(number !=null){
  98.                                         System.out.println(windowName +"为第"+number+"号"+type +"客服服务");
  99.                                         long beginTime = System.currentTimeMillis();
  100.                                         try {
  101.                                                 Thread.sleep(serverTime);
  102.                                         } catch (InterruptedException e) {
  103.                                                 // TODO Auto-generated catch block
  104.                                                 e.printStackTrace();
  105.                                         }
  106.                                         long costTime = System.currentTimeMillis()-beginTime;
  107.                                         System.out.println(windowName +"为第"+number+"号"+type +
  108.                                                         "客服服务完成,耗时"+costTime/1000+"秒");
  109.                                        
  110.                                 }else{
  111.                                         System.out.println("没有获取到任务。");
  112.                                         commonService();
  113.                                         expressService();               
  114.                                        
  115.                                 }
  116.                         }
  117.          
  118. }
复制代码
打印结果没有看见快速窗口为快速客服服务,vip也不为普通窗口服务。 求解决

评分

参与人数 1技术分 +1 收起 理由
EYE_SEE_YOU + 1

查看全部评分

1 个回复

倒序浏览

{:soso_e176:}
亲,请问下问题是否解决?
如果已解决请及时将未解决改为已解决
如果未解决请回帖追问
三天未回复的将视为已解决
详情参考:如何更改分类

保持队形,谢谢合作
{:soso_e181:}
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 加入黑马