Created
November 25, 2014 02:09
-
-
Save RaviH/6222db0f50ab0a7b12ae to your computer and use it in GitHub Desktop.
Spring Batch Retry with Timeout
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import com.rackspace.monitoring.BaseLoggingThing | |
import org.springframework.retry.RetryCallback | |
import org.springframework.retry.RetryContext | |
import org.springframework.retry.policy.TimeoutRetryPolicy | |
import org.springframework.retry.support.RetryTemplate | |
class TimeoutRetryExample extends BaseLoggingThing { | |
RetryTemplate retryTemplate = new RetryTemplate() | |
CarRepository carRepository | |
TimeoutRetryExample(com.rackspace.monitoring.atomhopper.CarRepository carRepository, int timeoutInSecs) { | |
this.carRepository = carRepository | |
TimeoutRetryPolicy timeoutRetryPolicy = new TimeoutRetryPolicy() | |
timeoutRetryPolicy.timeout = timeoutInSecs * 1000L | |
retryTemplate.retryPolicy = timeoutRetryPolicy | |
} | |
String getCar(final String make) { | |
return retryTemplate.execute(new RetryCallback() { | |
@Override | |
String doWithRetry(RetryContext retryContext) throws Exception { | |
// A long operation is simulated here. | |
sleep(1000) | |
return carRepository.findCarNameByMake(make) | |
} | |
}) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment