Scenario : I need to modify maxAttempts value of @Retryable
at runtime, so that the number of retries can be driven from database
@Service
public class PropertyHolder {
private int retryCount= 2;
public int retryCount() { return retryCount; }
@Scheduled(fixedRate=3600000) //Query DB and update retryCount every 60mins
private void updateRetryCount(int in) {
this.retryCount = 0; //Fetch retryCount from DB and update retryCount
}
}
@Service
public class SimpleService{
@Retryable( value={ Throwable.class }, maxAttemptsExpression="#{@propertyHolder.retryCount()}")
private void performTask() {
// do some opertion that throws Exception
}
}
PropertyHolder
will update retryCount
once in every 60 minutes.
This PropertHolder#retryCount
needs to be wired to @Retryable
in SimpleService#performTask
.
At present, it takes only the initial value of retryCount (2).
Is this a right approach or Am I making some terrible mistake?