2016-02-05 58 views
-1

我有很多服務任務調用休息服務,有時服務不可用。我想在我的JavaDelegate能夠無限次重試作業:503錯誤後活動重試作業

@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

我覺得這是一個做事的馬虎的方式,但如果你確信這是你想要做什麼,我建議你做這樣的事情:

@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); 
     } 
    } 
}