Java Thread Callable repeatedlyTry(Callable task, int maxRounds, long backoff)

Here you can find the source of repeatedlyTry(Callable task, int maxRounds, long backoff)

Description

repeatedly Try

License

Open Source License

Declaration

public static <T> T repeatedlyTry(Callable<T> task, int maxRounds,
            long backoff) throws Exception 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.util.LinkedList;
import java.util.List;

import java.util.concurrent.Callable;

public class Main {
    public static <T> T repeatedlyTry(Callable<T> task, int maxRounds,
            long backoff) throws Exception {
        List<Exception> list = new LinkedList<Exception>();
        int round = 0;
        while (round++ < maxRounds) {
            try {
                return task.call();
            } catch (Exception e) {
                list.add(e);/*from  w  w w  .  ja v  a2 s . com*/
                try {
                    Thread.sleep(backoff);
                } catch (InterruptedException e1) {
                    e1.printStackTrace();
                }
            }
        }
        throw new Exception("can't run: " + list);
    }
}

Related

  1. invokeAll(Collection> tasks, ExecutorService executorService)
  2. invokeBulkActions(Collection> tasks)
  3. max(final double[] a, final double[] b)
  4. minScalar(final double[] a, final double scalar)
  5. powerTo(final double base, final double[] exponents)
  6. resolveCompositeKey(final String key, final Map props)
  7. resolveSingle(Object object)
  8. runAndRethrowRuntimeExceptionOnFailure(final Callable operation, final String exceptionMessage)
  9. runConcurrently(final Callable task)