public final class CismetExecutors extends Object
Executors except that the ExecutorServicees created by this class will inform
an Thread.UncaughtExceptionHandler in case of a call to any of the ExecutorService' submit
operations. The default Executors will not inform an UncaughtExceptionHandler because it
assumes that a 'submitter' is responsible for calling Future.get() to retrieve the execution result which
results in an ExecutionException in case of an error during execution. However, this may result in uncaught
and thus 'invisible' exceptions and hence it gets very hard to trace errors if the get() operation will
never be called, e.g. because the Future is not directly used by the 'submitter' but delegated to
another operation or propagated up the call-stack as a return value, etc.ExecutorService: The 'CachedLimitedThreadPool': It
behaves like an ordinary 'CachedThreadPool' thus increasing and shrinking in size with respect to the current
workload but unlike the 'CachedThreadPool' it can get full, too, similar to the 'FixedThreadPool'.ScheduledExecutorService not supported yet, but will be added soon.ExecutorServices if you are not sure if an
UncaughtExceptionHandler may somehow interfere with the handling that will be done in case of an
ExecutionException! Also keep in mind that it may occur that an exception is handled twice: via
get() or the resulting ExecutionException, respectively, if called at all and via the
UncaughtExceptionHandler if registered.| Modifier and Type | Class and Description |
|---|---|
static class |
CismetExecutors.UEHThreadPoolExecutor
Extension of the
ThreadPoolExecutor that keeps track of the executed tasks and informs the
Thread.UncaughtExceptionHandler associated with the executing thread in case of an exception during task
execution. |
public static ExecutorService newCachedLimitedThreadPool(int maxThreads, String prefix)
newCachedLimitedThreadPool(int, java.util.concurrent.ThreadFactory, java.util.concurrent.RejectedExecutionHandler)
with a null RejectedExecutionHandler and a ThreadFactory that is created using the
prefix parameter as name of the ThreadFactory.maxThreads - max amount of threads this ExecutorService will ever createprefix - prefix used for the generation of the ThreadFactoryExecutorServicenewCachedLimitedThreadPool(int, java.util.concurrent.ThreadFactory,
java.util.concurrent.RejectedExecutionHandler)public static ExecutorService newCachedLimitedThreadPool(int maxThreads, ThreadFactory threadFactory)
newCachedLimitedThreadPool(int, java.util.concurrent.ThreadFactory, java.util.concurrent.RejectedExecutionHandler)
with a null RejectedExecutionHandler.maxThreads - max amount of threads this ExecutorService will ever createthreadFactory - the ThreadFactory that will be responsible for the creation of new threadsExecutorServicenewCachedLimitedThreadPool(int, java.util.concurrent.ThreadFactory,
java.util.concurrent.RejectedExecutionHandler)public static ExecutorService newCachedLimitedThreadPool(int maxThreads, ThreadFactory threadFactory, RejectedExecutionHandler rejectHandler)
ExecutorService that is dynamic like a CachedThreadPool but has an upper bound
of threads executed in parallel. The ExecutorService has the following properties:0 threads if there are no tasksmaxThreads(maxThreads + 1) * 2 / 3 tasks queued for executionThreadPoolExecutor.AbortPolicy as RejectedExecutionHandler if the given handler is nullmaxThreads + ((maxThreads + 1) * 2 / 3)
at once for execution. Any supernumerous threads are rejected! By default the AbortPolicy kicks in
then which means that an RejectedExecutionException is thrown.maxThreads - max amount of threads this ExecutorService will ever createthreadFactory - the ThreadFactory that will be responsible for the creation of new threadsrejectHandler - the RejectedExecutionHandler that will handle rejected executions, the
AbortPolicy by default.ExecutorServiceThreadPoolExecutorpublic static ExecutorService newFixedThreadPool(int nThreads)
Executors.newFixedThreadPool(int)public static ExecutorService newFixedThreadPool(int nThreads, ThreadFactory threadFactory)
public static ExecutorService newSingleThreadExecutor()
Executors.newSingleThreadExecutor()public static ExecutorService newSingleThreadExecutor(ThreadFactory threadFactory)
public static ExecutorService newCachedThreadPool()
Executors.newCachedThreadPool()public static ExecutorService newCachedThreadPool(ThreadFactory threadFactory)
Copyright © 2012–2026 cismet GmbH. All rights reserved.