Multi-tree abstract task dependency and cross-tree Abstraction

Source: Internet
Author: User

Multi-tree abstract task dependency and cross-tree Abstraction

 

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.

For example:

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 BaseTask 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 executed by each task process; 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 abstraction has too many limitations. concatenating all tasks will cause tasks to be manually split, and dependencies are embedded into code, which is difficult to maintain. In addition, the multi-task dependency still does not meet the requirements.

Therefore, a more powerful task scheduling system is required to implement this flexible task dependency.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.