我正在执行一项任务,其中我需要执行 5-6 个步骤,如果我的代码在中间的某个步骤失败,我的要求是从失败的同一步骤重试(此信息我在数据库中维护table),我可以通过复杂的 if-else 检查来解决这个问题,但我正在寻找一些标准或好的方法来解决这个问题。
I'd keep a list of subtasks and an index to specify where the execution stoped. Pseudocode:
public class Task {
List<SubTask> subtasks;
int executionIndex = 0;
// ctor, getters, setters, etc...
public void execute() {
for (int i = executionIndex; i < subtasks.size(); ++i) {
subtasks.get(i).execute();
saveProgressToDB(i);
++exectionIndex;
}
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.