List of utility methods to do Thread Executor
void | addExecutorShutdownHook(final ExecutorService exec) add Executor Shutdown Hook addExecutorShutdownHook(exec, 60, TimeUnit.SECONDS); |
void | addThread(Runnable runnable) add Thread service.execute(runnable); |
Callable | convert(Runnable runnable, T result) Converts the specified Runnable to a Callable returning the specified result. return () -> { runnable.run(); return result; }; |
int | getActiveHelperInstanceCount(String helperName) get Active Helper Instance Count return ((ThreadPoolExecutor) executorServiceMap.get(helperName)).getActiveCount();
|
ExecutorService | getChannelService() get Channel Service return CHANNEL_SERVICE;
|
Map | getConstantLookup() get Constant Lookup Map<String, String> toRet = new HashMap<>(); toRet.put("java.util.concurrent.BlockingDeque", "BLOCKING_DEQUE"); toRet.put("java.util.concurrent.BlockingQueue", "BLOCKING_QUEUE"); toRet.put("java.util.concurrent.Callable", "CALLABLE"); toRet.put("java.util.concurrent.CompletionService", "COMPLETION_SERVICE"); toRet.put("java.util.concurrent.ConcurrentMap", "CONCURRENT_MAP"); toRet.put("java.util.concurrent.ConcurrentNavigableMap", "CONCURRENT_NAVIGABLE_MAP"); toRet.put("java.util.concurrent.Delayed", "DELAYED"); ... |
ExecutorService | getThreadExecutor(int nThreads) get Thread Executor return Executors.newFixedThreadPool(nThreads);
|
boolean | isCorrectCollectionSizeTimeOut(Collection> collection, int size, long timeout, TimeUnit unit) Check size of a collection populated in another thread. Runnable task = () -> { try { while (collection.size() != size) { TimeUnit.MILLISECONDS.sleep(10); } catch (InterruptedException e) { throw new IllegalStateException("task interrupted", e); }; ExecutorService executor = Executors.newSingleThreadExecutor(); executor.submit(task); executor.shutdown(); return executor.awaitTermination(timeout, unit); |
boolean | isRegularlyDone(Future> future) Checks if the specified Future terminated regularly, e.g. try { future.get(); } catch (InterruptedException | ExecutionException e) { return false; return true; |
boolean | isShutdown(Executor executor) is Shutdown if (executor instanceof ExecutorService) { if (((ExecutorService) executor).isShutdown()) { return true; return false; |