Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 package net.dataforte.commons.concurrent;
 
 
 
This class implements a java.util.concurrent.Callable which can be retried a specified number of times before failing

Parameters:
<T>
Author(s):
Tristan Tarrant
public class RetryCallable<T> implements Callable<T> {
	private final Callable<T> callable;
	private final int maxRetries;
	private final Logger log = LoggerFactory.make();
	public RetryCallable(Callable<T> callableint retryCount) {
		this. = callable;
		this. = retryCount;
	}
	public T call() throws Exception {
		int retry = 0;
		for(;;) {
			try {
				return .call();
catch (final InterruptedException e) {
				throw e;
catch (final CancellationException e) {
				throw e;
catch (final Exception e) {
				++retry;
				if (retry == )
					throw e;
				.warn(.toString()+" threw exception "+e.getMessage()+" on try "+retry+"/"+);
			}
		}
	}
New to GrepCode? Check out our FAQ X