我有这样的方法:
public void runMethod()
{
method1();
method2();
method3();
}
Run Code Online (Sandbox Code Playgroud)
我想根据id多次调用此runMethod.但是,如果说method2()由于某种原因失败,那么当我调用runMethod时,它应该执行method3()而不是再次尝试执行method1()(已经成功运行此id).
实现这一目标的最佳方法是什么?
非常感谢您的帮助
您可以在映射中记录方法是否成功执行。
private Map<String, Boolean> executes = new HashMap<String, Boolean>();
public void method1() {
Boolean hasExecuted = executes.get("method1");
if (hasExecuted != null && hasExecuted) {
return;
}
executes.put("method1", true);
...
}
// and so forth, with method2, method3, etc
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
187 次 |
| 最近记录: |