/** * 过程执行器 * * @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; } }
do1... do2... do3... do4... do5... ------------------ do3... do4... do5... ------------------ do5... Process finished with exit code 0
一个流程执行器的简单实现
时间: 2024-10-30 03:12:17