Multi-tree abstract task dependency
When the system is idle, it can run some tasks to perform some statistical operations. Most of them are data retrieval, data insertion, and statistical data. These tasks are sometimes dependent. For example, if task A is counted as dependent on Task B, Task B is scheduled to run at the beginning of the year, and task A runs, however, if Task B cannot be completed within one hour, A problem may occur when running task. You must ensure that task B is completed before running task. Therefore, we can consider using a linked list data structure to concatenate tasks for execution, and ensure that the business of each task is separated on the Code layer. BaseTask: public abstract class BaseTask {private String id; public abstract void execute (); public String getId () {return id;} public void setId (String id) {this. id = id ;}} SimpleBaseTask: public abstract class SimpleBaseTask extends BaseTask {public void execute () {beforeExecute (); doTask (); doNextTask (); afterExecute ();} public void doNextTask () {if (nextTasks! = Null) {for (BaseTask task: nextTasks) {task.exe cute () ;}} public abstract void beforeExecute (); public abstract void afterExecute (); public abstract void doTask (); private String name; private BaseTask parentTask; // each task can have multiple subsequent tasks. These tasks depend on the execution completion of this task. private List <BaseTask> nextTasks; public String getName () {return name ;} public void setName (String name) {this. name = name;} public BaseTas K getParentTask () {return parentTask;} public void setParentTask (BaseTask parentTask) {this. parentTask = parentTask;} public List <BaseTask> getNextTasks () {return nextTasks;} public void setNextTasks (List <BaseTask> nextTasks) {this. nextTasks = nextTasks;} ProcessGroup: public abstract class ProcessGroup <T extends BaseTask >{// the first task logic private BaseTask firstTask; public BaseTask GetFirstTask () {return firstTask;} public void setFirstTask (BaseTask firstTask) {this. firstTask = firstTask;} public abstract void beforeProcess (); public abstract void afterProcess (); public void doProcess () {beforeProcess (); firstTask.exe cute (); afterProcess ();}} simpleProcessGroup: public class SimpleProcessGroup extends ProcessGroup <SimpleBaseTask >{@ Override public void beforeProcess () {System. out. println ("beforeProcess") ;}@ Override public void afterProcess () {System. out. println ("afterProcess");} This abstract has too many limitations. concatenating all tasks will cause the tasks to be manually split, and the dependency is embedded into the code, which is difficult to maintain. In addition, the multi-task dependency still does not meet the requirements.