package com.huida.bank; import java.util.Random; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; public class ServiceWindow { private Type type=Type.common; private int id=1;//´°¿Ú Integer commonnum=null;//ÆÕͨÓû§±àºÅ Integer fastnum=null;//¿ìËÙÓû§±àºÅ Integer vipnum=null;//vipÓû§±àºÅ public void setType(Type type){ this.type=type; } public void setid(int id){ this.id=id; } public void start(){ ExecutorService pool=Executors.newSingleThreadExecutor(); pool.execute(new Runnable(){ public void run(){ while(true){ switch(type){ case common: common(); break; case fast: fast(); break; case vip: vip(); break; } } } }); } //¶¨Òå´¦ÀíÆÕͨ¿Í»§Âß¼·½·¨ public void common(){ commonnum=NumberMachine.getnumberMachine().getcommonManager().getNumber(); if(commonnum!=null){ System.out.println("µÚ"+id+"¸ö"+type+"´°¿Ú×¼±¸Îª"+commonnum+"¿Í»§·þÎñ"); long startTime=System.currentTimeMillis(); int time=Time.MAX_TIME-Time.MIN_TIME+1; int randTime=new Random().nextInt(time)+Time.MIN_TIME;//nextInt()0-9Ö®¼äµÄËæ»úÊý try { Thread.sleep(randTime*1000); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } long endTime=System.currentTimeMillis(); long serviceTime=endTime-startTime; System.out.println("µÚ"+id+"¸ö"+type+"´°¿ÚΪ"+commonnum+"¿Í»§·þÎñ"+(serviceTime/1000)+"Ãë"); }else{ System.out.println("ûÓÐÆÕͨ¿Í»§,ÏÈÐÝÏ¢Ò»Ãë"); try { Thread.sleep(1000); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } public void fast(){ fastnum=NumberMachine.getnumberMachine().getfastManager().getNumber(); if(fastnum!=null){ System.out.println("µÚ"+id+"¸ö"+type+"´°¿Ú×¼±¸Îª"+fastnum+"¿Í»§·þÎñ"); long startTime=System.currentTimeMillis(); try { Thread.sleep(Time.MIN_TIME*1000); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } long endTime=System.currentTimeMillis(); long serviceTime=endTime-startTime; System.out.println("µÚ"+id+"¸ö"+type+"´°¿ÚΪ"+fastnum+"¿Í»§·þÎñ"+(serviceTime/1000)+"Ãë"); }else{ System.out.println("ûÓпìËÙ¿Í»§£¬Òª×¼±¸ÎªÆÕͨ¿Í»§·þÎñ"); common(); } } public void vip(){ vipnum=NumberMachine.getnumberMachine().getvipManager().getNumber(); if(vipnum!=null){ System.out.println("µÚ"+id+"¸ö"+type+"´°¿Ú×¼±¸Îª"+vipnum+"¿Í»§·þÎñ"); long startTime=System.currentTimeMillis(); int time=Time.MAX_TIME-Time.MIN_TIME+1; int randTime=new Random().nextInt(time)+1+Time.MIN_TIME; try { Thread.sleep(randTime*1000); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } long endTime=System.currentTimeMillis(); long serviceTime=endTime-startTime; System.out.println("µÚ"+id+"¸ö"+type+"´°¿ÚΪ"+vipnum+"¿Í»§·þÎñ"+(serviceTime/1000)+"Ãë"); }else{ System.out.println("ûÓÐvip¿Í»§£¬Òª×¼±¸ÎªÆÕͨ¿Í»§·þÎñ"); common(); } } }