public class GenericOperationUtil extends Object
Constructor and Description |
---|
GenericOperationUtil() |
Modifier and Type | Method and Description |
---|---|
static <R> R |
executeRetryableOperation(GenericOperation<R> operation)
Executes the provided operation up to 5 times if there are exceptions, waiting an additive 100 ms between tries.
|
static <R> R |
executeRetryableOperation(GenericOperation<R> operation,
Class<? extends Exception>[] noRetriesForException)
Executes the provided operation up to 5 times if there are exceptions, waiting an additive 100 ms between tries.
|
static <R> R |
executeRetryableOperation(GenericOperation<R> operation,
int retries,
long waitTime,
boolean isWaitTimesAdditive,
Class<? extends Exception>[] noRetriesForException)
Executes the provided operation up to as many times as the retries argument.
|
public static <R> R executeRetryableOperation(GenericOperation<R> operation) throws Exception
InterruptedException
.operation
- Exception
public static <R> R executeRetryableOperation(GenericOperation<R> operation, Class<? extends Exception>[] noRetriesForException) throws Exception
InterruptedException
.operation
- noRetriesForException
- Exception
public static <R> R executeRetryableOperation(GenericOperation<R> operation, int retries, long waitTime, boolean isWaitTimesAdditive, Class<? extends Exception>[] noRetriesForException) throws Exception
retries
times. The wait time is the amount of time that this method will wait between tries. If isWaitTimesAdditive
, then the waitTime parameter
will be multiplied by the current retry iteration each time. Otherwise, the waitTime will not change between tries.
If retries == 5, waitTime == 100, and isWaitTimesAdditive == false, then the total wait time, assuming no successful iterations, will be 500 milliseconds (100 + 100 + 100 + 100 + 100).
If retries == 5, waitTime == 100, and isWaitTimesAdditive == true, then the total wait time, assuming no successful iterations, will be 1500 milliseconds (100 + 200 + 300 + 400 + 500).
This will never retry for an InterruptedException
.operation
- retries
- waitTime
- isWaitTimesAdditive
- noRetriesForException
- Exception
Copyright © 2022. All rights reserved.