-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathServiceWindow.java
More file actions
106 lines (104 loc) · 2.98 KB
/
Copy pathServiceWindow.java
File metadata and controls
106 lines (104 loc) · 2.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
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();
}
}
}