List of utility methods to do Thread Callable
Callable | powerTo(final double base, final double[] exponents) power To Callable c = new Callable() { public Object call() throws Exception { double[] result = new double[exponents.length]; for (int i = 0; i < exponents.length; i++) { result[i] = Math.pow(base, exponents[i]); return result; }; return c; |
T | repeatedlyTry(Callable repeatedly Try List<Exception> list = new LinkedList<Exception>(); int round = 0; while (round++ < maxRounds) { try { return task.call(); } catch (Exception e) { list.add(e); try { ... |
String | resolveCompositeKey(final String key, final Map resolve Composite Key String value = null; final int comma = key.indexOf(','); if (comma > -1) { if (comma > 0) { final String key1 = key.substring(0, comma); if (props != null) { Object o = props.get(key1); if (o instanceof Callable) { ... |
Object | resolveSingle(Object object) resolve Single try { return object instanceof Callable ? ((Callable<?>) object).call() : object; } catch (Exception e) { throw new RuntimeException(e); |
T | runAndRethrowRuntimeExceptionOnFailure(final Callable Runs the specified operation and re-throws any checked exception as RuntimeException. try { return operation.call(); } catch (Exception e) { if (e instanceof RuntimeException) { throw (RuntimeException) e; } else { throw new RuntimeException(exceptionMessage, e); |
void | runConcurrently(final Callable Runs a task concurrently. final ExecutorService service = Executors.newFixedThreadPool(5); final List<Future<?>> futures = new ArrayList<Future<?>>(); for (int i = 0; i < 10; i++) { futures.add(service.submit(task)); for (final Future<?> future : futures) { future.get(); |
void | runConcurrently(final Callable Run the task concurrently 100 times. runConcurrently(task, 100); |
void | runConcurrently(final Callable Runs a task concurrently. final ExecutorService service = Executors.newFixedThreadPool(5); final List<Future<?>> futures = new ArrayList<Future<?>>(); for (int i = 0; i < times; i++) { futures.add(service.submit(task)); for (final Future<?> future : futures) { future.get(); |
Void | runInBackground(final Callable run In Background new Thread(new Runnable() { public void run() { try { callable.call(); } catch (Exception e) { e.printStackTrace(); }).start(); return null; |
void | runTest(Callable run Test try { test.call(); } catch (RuntimeException e) { if ("org.autorefactor.util.UnhandledException".equals(e.getClass().getName()) || "Unexpected exception".equals(e.getMessage())) { throw (Exception) e.getCause(); throw e; ... |