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
|
/** * 过程执行器
*
* @author leizhimin 2014/8/7 17:15
*/
public class Test {
public static void main(String[] args) {
dotask( new Task( 0 ));
System.out.println( "------------------" );
dotask( new Task( 2 ));
System.out.println( "------------------" );
dotask( new Task( 4 ));
}
private static void dotask(Task task) {
switch (task.getState()) {
case 0 :
do1(task);
break ;
case 1 :
do2(task);
break ;
case 2 :
do3(task);
break ;
case 3 :
do4(task);
break ;
case 4 :
do5(task);
break ;
default :
break ;
}
}
private static void do1(Task task) {
System.out.println( "do1..." );
task.setState( 1 );
dotask(task);
}
private static void do2(Task task) {
System.out.println( "do2..." );
task.setState( 2 );
dotask(task);
}
private static void do3(Task task) {
System.out.println( "do3..." );
task.setState( 3 );
dotask(task);
}
private static void do4(Task task) {
System.out.println( "do4..." );
task.setState( 4 );
dotask(task);
}
private static void do5(Task task) {
System.out.println( "do5..." );
task.setState( 5 );
dotask(task);
}
} class Task {
private int state;
Task( int state) {
this .state = state;
}
public int getState() {
return state;
}
public void setState( int state) {
this .state = state;
}
} |
1
2
3
4
5
6
7
8
9
10
11
12
13
|
do1... do2... do3... do4... do5... ------------------ do3... do4... do5... ------------------ do5... Process finished with exit code 0
|
本文转自 leizhimin 51CTO博客,原文链接:http://blog.51cto.com/lavasoft/1537506,如需转载请自行联系原作者