Package com.sedmelluq.lava.common.tools
Class ExecutorTools
- java.lang.Object
-
- com.sedmelluq.lava.common.tools.ExecutorTools
-
public class ExecutorTools extends java.lang.ObjectUtility methods for working with executors.
-
-
Field Summary
Fields Modifier and Type Field Description static com.sedmelluq.lava.common.tools.ExecutorTools.CompletedVoidFutureCOMPLETED_VOIDA completed Future<Void> instance.
-
Constructor Summary
Constructors Constructor Description ExecutorTools()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static java.util.concurrent.ThreadPoolExecutorcreateEagerlyScalingExecutor(int coreSize, int maximumSize, long timeout, int queueCapacity, java.util.concurrent.ThreadFactory threadFactory)Creates an executor which will use the queue only when maximum number of threads has been reached.static voidshutdownExecutor(java.util.concurrent.ExecutorService executorService, java.lang.String description)Shut down an executor and log the shutdown result.
-
-
-
Method Detail
-
shutdownExecutor
public static void shutdownExecutor(java.util.concurrent.ExecutorService executorService, java.lang.String description)Shut down an executor and log the shutdown result. The executor is given a fixed amount of time to shut down, if it does not manage to do it in that time, then this method just returns.- Parameters:
executorService- Executor service to shut downdescription- Description of the service to use for logging
-
createEagerlyScalingExecutor
public static java.util.concurrent.ThreadPoolExecutor createEagerlyScalingExecutor(int coreSize, int maximumSize, long timeout, int queueCapacity, java.util.concurrent.ThreadFactory threadFactory)Creates an executor which will use the queue only when maximum number of threads has been reached. The core pool size here only means the number of threads that are always alive, it is no longer used to check whether a new thread should start or not. The maximum size is otherwise pointless unless you have a bounded queue, which in turn would cause tasks to be rejected if it is too small.- Parameters:
coreSize- Number of threads that are always alivemaximumSize- The maximum number of threads in the pooltimeout- Non-core thread timeout in millisecondsthreadFactory- Thread factory to create pool threads with- Returns:
- An eagerly scaling thread pool executor
-
-