| 本帖最后由 何伟超 于 2014-3-8 15:09 编辑 
 银行项目系统有一处不理解
 我写到窗口类里面
 
 这个里面有个 long servicetime =new Random().nextInt(costTime)+1; 服务时间复制代码import java.util.Random;
import java.util.concurrent.Executors;
public class serviceWindow {
        private Customer cust=Customer.COMMON;//默认为普通
        private int WindowID = 1;//定义提个窗口号码
        public void setCust(Customer cust) {
                this.cust = cust;
        }
        public void setWindowID(int windowID) {
                WindowID = windowID;
        }
        //这里设立一个启动方法
        public void start(){
                Executors.newSingleThreadExecutor().execute(new Runnable() {
                        
                        @Override
                        public void run() {
                                // TODO Auto-generated method stub
                                //这里一定是不停的取号
                                while(true){
                                        switch(cust){
                                        case COMMON:
                                                String windowName = "第"+WindowID+"号"+cust+"窗口";
                                                System.out.println("正在获取任务");
                                                Integer  commonNumber =                 NumberMachine.getIntance().getCommonManager().fetchServiceNumber();//拿到普通用户号码
                                                if(commonNumber!=null){
                                                        long starttime =  System.currentTimeMillis();
                                                        int costTime = timeCount.MaxServiceTime-timeCount.MinServiceTime;
                                                        long servicetime =new Random().nextInt(costTime)+1;
                                                        try {
                                                                Thread.sleep(servicetime);//服务
                                                        } catch (InterruptedException e) {
                                                                // TODO Auto-generated catch block
                                                                e.printStackTrace();
                                                        }
                                                        long  time = System.currentTimeMillis()-starttime;
                                                        System.out.println(windowName+"为第"+commonNumber+"个"+cust+"客户进行服务 耗时:"+time+"秒");
                                                        
                                                }
                                                else{
                                                        
                                                        System.out.println("没有取到号");
                                                }
                                        break;
                                        case VIP:
        int VIPNumber =         NumberMachine.getIntance().getVipManager().fetchServiceNumber();//拿到VIP用户号码
                                                break;
                                        case EXPRESS:
        int ExpressNumber =                NumberMachine.getIntance().getExcepressManager().fetchServiceNumber();//拿到快速用户号码
                                        }
                                }
                                
                        }
                });
                
                
        }
}
当然 我们前面也定义了一个类
 
 这个是设置最大最小时间的复制代码public class timeCount {
        public static int MaxServiceTime=10000;//设置最大时间
        public static int MinServiceTime=1000;//设置最小时间
}
我想问的是 new Random().nextInt(costTime)不就是1000-9000的随机值 么 后面加上timeCount.MinServiceTime
 是1-10000的话 那么
 
 复制代码long servicetime =new Random().nextInt(costTime)+1+timeCount.MinServiceTime;
这里的 +1 是否多余了呢  求大神解答:)
 
 
 |