-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTest.java
More file actions
72 lines (57 loc) · 2.1 KB
/
Copy pathTest.java
File metadata and controls
72 lines (57 loc) · 2.1 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
package processor;
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;
/**
* Created by focus on 2018/3/16.
*/
public class Test {
public static void main(String[] args) throws Exception {
Test t = new Test();
List<IProcessor> list = new CopyOnWriteArrayList<>();
list.add(new Process1("任务一",true));
list.add(new Process1("任务二",true));
list.add(new Process1("任务三",false));
list.add(new Process1("任务四",false));
list.add(new Process1("任务五",true));
list.add(new Process1("任务六",true));
list.add(new Process1("任务七",true));
long start = System.currentTimeMillis();
ProcessorExecuteService processorPool = new ProcessorExecuteService(list);
processorPool.executeAsync();
System.out.println("end execute: " + (System.currentTimeMillis() - start));
System.out.println(processorPool.getProcessorResult("任务一"));
System.out.println(processorPool.getProcessorResult("任务二"));
System.out.println(processorPool.getProcessorResult("任务三"));
System.out.println(processorPool.getProcessorResult("任务四"));
System.out.println(processorPool.getProcessorResult("任务五"));
System.out.println(processorPool.getProcessorResult("任务六"));
System.out.println(processorPool.getProcessorResult("任务七"));
System.out.println("end get : " + (System.currentTimeMillis() - start));
}
}
class Process1 implements IProcessor {
private Boolean isAsync;
private String id;
Process1(String id,boolean isAsync){
this.isAsync = isAsync;
this.id = id;
}
@Override
public String id() {
return id;
}
@Override
public boolean isAsyn() {
return isAsync;
}
@Override
public Object process() {
try {
Thread.sleep(1000l);
} catch (InterruptedException e) {
e.printStackTrace();
}
System.out.println(" hello " + id() + " isAsync " + isAsyn());
return id();
}
}