Class ScalingThreadPoolExecutor
- java.lang.Object
-
- java.util.concurrent.AbstractExecutorService
-
- java.util.concurrent.ThreadPoolExecutor
-
- net.automatalib.common.util.concurrent.ScalingThreadPoolExecutor
-
- All Implemented Interfaces:
Executor,ExecutorService
public final class ScalingThreadPoolExecutor extends ThreadPoolExecutor
AThreadPoolExecutorthat internally uses aScalingThreadPoolExecutor.ScalingLinkedBlockingQueueto manage scheduled tasks. This allows us to manage a dynamically sized thread pool that actually spawns new threads when the pool still allows for it.Additionally, this implementation keeps track of the current number of active threads by using an
AtomicIntegercounter, rather than querying its list of worker threads.For further information, see this blog post.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class java.util.concurrent.ThreadPoolExecutor
ThreadPoolExecutor.AbortPolicy, ThreadPoolExecutor.CallerRunsPolicy, ThreadPoolExecutor.DiscardOldestPolicy, ThreadPoolExecutor.DiscardPolicy
-
-
Constructor Summary
Constructors Constructor Description ScalingThreadPoolExecutor(int corePoolSize, int maximumPoolSize, long keepAliveTime, TimeUnit unit)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidafterExecute(Runnable r, Throwable t)protected voidbeforeExecute(Thread t, Runnable r)intgetActiveCount()-
Methods inherited from class java.util.concurrent.ThreadPoolExecutor
allowCoreThreadTimeOut, allowsCoreThreadTimeOut, awaitTermination, execute, finalize, getCompletedTaskCount, getCorePoolSize, getKeepAliveTime, getLargestPoolSize, getMaximumPoolSize, getPoolSize, getQueue, getRejectedExecutionHandler, getTaskCount, getThreadFactory, isShutdown, isTerminated, isTerminating, prestartAllCoreThreads, prestartCoreThread, purge, remove, setCorePoolSize, setKeepAliveTime, setMaximumPoolSize, setRejectedExecutionHandler, setThreadFactory, shutdown, shutdownNow, terminated, toString
-
Methods inherited from class java.util.concurrent.AbstractExecutorService
invokeAll, invokeAll, invokeAny, invokeAny, newTaskFor, newTaskFor, submit, submit, submit
-
-
-
-
Constructor Detail
-
ScalingThreadPoolExecutor
public ScalingThreadPoolExecutor(int corePoolSize, int maximumPoolSize, long keepAliveTime, TimeUnit unit)
-
-
Method Detail
-
getActiveCount
public int getActiveCount()
- Overrides:
getActiveCountin classThreadPoolExecutor
-
beforeExecute
protected void beforeExecute(Thread t, Runnable r)
- Overrides:
beforeExecutein classThreadPoolExecutor
-
afterExecute
protected void afterExecute(Runnable r, Throwable t)
- Overrides:
afterExecutein classThreadPoolExecutor
-
-