Created
December 10, 2011 18:05
-
-
Save mauricio/1455790 to your computer and use it in GitHub Desktop.
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
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