Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 package uk.sponte.automation.seleniumpom.helpers;
 
Created by n450777 on 13/04/15.
 
 public class OperationHelper {
     public static void withRetry(int maxAttemptsRunnable runnablethrows RetryException {
        withRetry(maxAttempts, 500, runnable);
    }
    public static void withRetry(int maxAttemptsint delayRunnable runnablethrows RetryException {
        Exception exceptionThrown = null;
        for (int count = 0; count < maxAttemptscount++) {
            try {
                runnable.run();
                return;
            } catch (Exception e) {
                ..printf("[%s] Retrying %s%n because of %s %n"countrunnablee);
                exceptionThrown = e;
                sleep(delay);
            }
        }
        if(exceptionThrown != null) {
            throw new RetryException(exceptionThrown);
        }
    }
    public static void sleep(int ms) {
        try {
            Thread.sleep(ms);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
New to GrepCode? Check out our FAQ X