Java 503错误后的活动重试作业
我有许多服务任务称为rest服务,有时服务不可用。我希望在JavaDelegate中能够无限次重试作业:Java 503错误后的活动重试作业,java,activiti,Java,Activiti,我有许多服务任务称为rest服务,有时服务不可用。我希望在JavaDelegate中能够无限次重试作业: @Override public void execute(DelegateExecution execution) { try { //call_rest_service } catch (Exception503 error) { CommandContext commandContext = Context.get
@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
}
}
但这似乎不起作用 我认为这是一种草率的做事方式,但如果你确定这就是你想要做的,我建议你做如下事情:
@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);
}
}
}
@覆盖
公共作废执行(委托执行)
{
int retryMax=10,retryCount=0;
while(retryCount++