List of utility methods to do Thread Callable
V | executeUntilNonNullOrTimeout(final long timeoutMs, final long timeBetweenPollsMs, final Callable execute Until Non Null Or Timeout final long started = new Date().getTime(); long elapsedTime = 0; while (elapsedTime < timeoutMs) { final V value; try { value = callable.call(); } catch (Exception e) { throw new RuntimeException(e); ... |
T | executeWithClassLoader(ClassLoader classLoader, Callable Execute the call within the given class loader... ClassLoader previousClassLoader = Thread.currentThread().getContextClassLoader(); try { Thread.currentThread().setContextClassLoader(classLoader); return callable.call(); } finally { Thread.currentThread().setContextClassLoader(previousClassLoader); |
void | expectException(Callable> callable, Class> exception) expect Exception boolean thrown = false; try { callable.call(); } catch (Throwable e) { assert e.getClass().equals(exception) : e.getClass().getName() + " is not " + exception.getName(); thrown = true; assert thrown : exception.getName() + " not received"; ... |
byte[] | getBytes(final String string) Returns the bytes with "UTF-8" encoding from the specified string. return getBytes(string, "UTF-8"); |
Future | getFuture(ExecutorService executorService, Callable Get a future from a given callable. return executorService.submit(callable);
|
Object | getRandomValueForPrimitive(Class> type) get Random Value For Primitive Callable<Object> c = p2r.get(type); if (c == null) return null; try { return c.call(); } catch (Exception e) { throw new RuntimeException(e); |
List | invokeAll(Collection Invokes and waits all tasks using threadPool, avoiding thread starvation on the way (see "A Thread Pool Puzzler"). if (executorService == null) { for (Callable<T> task : tasks) { task.call(); return null; List<Future<T>> futures = new ArrayList<Future<T>>(tasks.size()); boolean done = false; ... |
void | invokeBulkActions(Collection invoke Bulk Actions invokeBulkActions(tasks, 20); |
Callable | max(final double[] a, final double[] b) max if (a.length != b.length) throw new Exception(""); Callable c = new Callable() { public Object call() throws Exception { double[] result = new double[a.length]; for (int i = 0; i < a.length; i++) { result[i] = Math.max(a[i], b[i]); return result; }; return c; |
Callable | minScalar(final double[] a, final double scalar) min Scalar Callable c = new Callable() { public Object call() throws Exception { double[] result = new double[a.length]; for (int i = 0; i < a.length; i++) { result[i] = Math.min(a[i], scalar); return result; }; return c; |