我有许多服务任务调用休息服务,有时服务不可用。我想在我的JavaDelegate中能够无限地重试这项工作:
@Override
public void execute(DelegateExecution execution)
{
try
{
//call_rest_service
}
catch (Exception503 error)
{
CommandContext commandContext = Context.getCommandContext();
JobEntity jobEntity = commandContext.getJobEntityManager().findById(job.getId());
jobEntity.setRetries(10);
//then throw original error
}
}
但这似乎不起作用!
答案 0 :(得分:0)
我认为这是一种 SLOPPY 做事的方式,但如果你确定这是你想做的事情,我建议你这样做:
@Override
public void execute(DelegateExecution execution)
{
int retryMax = 10, retryCount =0;
while (retryCount++ < retryMax){
try
{
//call_rest_service
}
catch (Exception503 error)
{
// sleep to not DDoS the server
Thread.sleep(500);
}
}
}