Java Utililty Methods Thread Executor

List of utility methods to do Thread Executor

Description

The list of methods to do Thread Executor are organized into topic(s).

Method

voidaddExecutorShutdownHook(final ExecutorService exec)
add Executor Shutdown Hook
addExecutorShutdownHook(exec, 60, TimeUnit.SECONDS);
voidaddThread(Runnable runnable)
add Thread
service.execute(runnable);
Callableconvert(Runnable runnable, T result)
Converts the specified Runnable to a Callable returning the specified result.
return () -> {
    runnable.run();
    return result;
};
intgetActiveHelperInstanceCount(String helperName)
get Active Helper Instance Count
return ((ThreadPoolExecutor) executorServiceMap.get(helperName)).getActiveCount();
ExecutorServicegetChannelService()
get Channel Service
return CHANNEL_SERVICE;
MapgetConstantLookup()
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");
...
ExecutorServicegetThreadExecutor(int nThreads)
get Thread Executor
return Executors.newFixedThreadPool(nThreads);
booleanisCorrectCollectionSizeTimeOut(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);
booleanisRegularlyDone(Future future)
Checks if the specified Future terminated regularly, e.g.
try {
    future.get();
} catch (InterruptedException | ExecutionException e) {
    return false;
return true;
booleanisShutdown(Executor executor)
is Shutdown
if (executor instanceof ExecutorService) {
    if (((ExecutorService) executor).isShutdown()) {
        return true;
return false;