Skip to content

Instantly share code, notes, and snippets.

@mauricio
Created December 10, 2011 18:05
Show Gist options
  • Save mauricio/1455790 to your computer and use it in GitHub Desktop.
Save mauricio/1455790 to your computer and use it in GitHub Desktop.
package br.com.faculdadeidez.loja.utils;
public abstract class ReturningRetryableService<T> {
private int maxRetries = 3;
private int retryCount = 0;
private T result;
public ReturningRetryableService() {
}
public abstract T execute();
public void run() {
Exception error = null;
while ( this.retryCount < this.maxRetries ) {
try {
this.result = this.execute();
error = null;
break;
} catch ( Exception e ) {
e.printStackTrace();
error = e;
this.retryCount++;
try {
Thread.sleep( 2500 );
} catch ( InterruptedException ie ) {
ie.printStackTrace();
}
}
}
if ( error != null ) {
throw new IllegalStateException(error);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment