Class CommonExecutorService
- java.lang.Object
-
- java.util.concurrent.AbstractExecutorService
-
- java.util.concurrent.ThreadPoolExecutor
-
- jetbrains.buildServer.util.executors.TeamCityThreadPoolExecutor
-
- jetbrains.buildServer.util.executors.ScalingThreadPoolExecutor
-
- jetbrains.buildServer.serverSide.impl.executors.CommonExecutorService
-
- All Implemented Interfaces:
Executor
,ExecutorService
,ScheduledExecutorService
,ExecutorServiceEx
public class CommonExecutorService extends ScalingThreadPoolExecutor implements ScheduledExecutorService
This is the common executor service each TeamCity service or plugin should use unless it requires a separate ExecutorService for some specific purpose.The idea behind is to use a single executor service for both scheduled and non-scheduled tasks.
Since the standard ScheduledExecutorService implementation - ScheduledThreadPoolExecutor (which can run immediate tasks also) is actually based on a fixed-sized thread pool, it's not very convenient for us because we want the number of threads running to vary depending on the workload.
That's why this implementation is based on the two JDK executor services - ScheduledThreadPoolExecutor and ThreadPoolExecutor.
The first one is used only for scheduled tasks while the other one is used for the tasks requiring immediate execution.
-
-
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 CommonExecutorService(int corePoolSize, int maximumPoolSize, int maximumQueueCapacity, long keepAliveTime, TimeUnit timeUnit, NamedThreadFactory threadFactory)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
awaitTermination(long timeout, TimeUnit unit)
boolean
isShutdown()
boolean
isTerminated()
ScheduledFuture<?>
schedule(Runnable command, long delay, TimeUnit unit)
<V> ScheduledFuture<V>
schedule(Callable<V> callable, long delay, TimeUnit unit)
ScheduledFuture<?>
scheduleAtFixedRate(Runnable command, long initialDelay, long period, TimeUnit unit)
ScheduledFuture<?>
scheduleWithFixedDelay(Runnable command, long initialDelay, long delay, TimeUnit unit)
void
shutdown()
List<Runnable>
shutdownNow()
-
Methods inherited from class jetbrains.buildServer.util.executors.ScalingThreadPoolExecutor
getMaxQueueCapacity, getQueue, getRejectsCount
-
Methods inherited from class jetbrains.buildServer.util.executors.TeamCityThreadPoolExecutor
afterExecute, beforeExecute, getName, getQueuedTasksCount, isPaused, newTaskFor, newTaskFor, pause, resume, setPoolSize
-
Methods inherited from class java.util.concurrent.ThreadPoolExecutor
allowCoreThreadTimeOut, allowsCoreThreadTimeOut, execute, finalize, getActiveCount, getCompletedTaskCount, getCorePoolSize, getKeepAliveTime, getLargestPoolSize, getMaximumPoolSize, getPoolSize, getRejectedExecutionHandler, getTaskCount, getThreadFactory, isTerminating, prestartAllCoreThreads, prestartCoreThread, purge, remove, setCorePoolSize, setKeepAliveTime, setMaximumPoolSize, setRejectedExecutionHandler, setThreadFactory, terminated, toString
-
Methods inherited from class java.util.concurrent.AbstractExecutorService
invokeAll, invokeAll, invokeAny, invokeAny, submit, submit, submit
-
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface java.util.concurrent.ExecutorService
invokeAll, invokeAll, invokeAny, invokeAny, submit, submit, submit
-
Methods inherited from interface jetbrains.buildServer.util.executors.ExecutorServiceEx
getActiveCount
-
-
-
-
Constructor Detail
-
CommonExecutorService
public CommonExecutorService(int corePoolSize, int maximumPoolSize, int maximumQueueCapacity, long keepAliveTime, TimeUnit timeUnit, NamedThreadFactory threadFactory)
-
-
Method Detail
-
schedule
@NotNull public ScheduledFuture<?> schedule(@NotNull Runnable command, long delay, @NotNull TimeUnit unit)
- Specified by:
schedule
in interfaceScheduledExecutorService
-
schedule
@NotNull public <V> ScheduledFuture<V> schedule(@NotNull Callable<V> callable, long delay, @NotNull TimeUnit unit)
- Specified by:
schedule
in interfaceScheduledExecutorService
-
scheduleAtFixedRate
@NotNull public ScheduledFuture<?> scheduleAtFixedRate(@NotNull Runnable command, long initialDelay, long period, @NotNull TimeUnit unit)
- Specified by:
scheduleAtFixedRate
in interfaceScheduledExecutorService
-
scheduleWithFixedDelay
@NotNull public ScheduledFuture<?> scheduleWithFixedDelay(@NotNull Runnable command, long initialDelay, long delay, @NotNull TimeUnit unit)
- Specified by:
scheduleWithFixedDelay
in interfaceScheduledExecutorService
-
shutdown
public void shutdown()
- Specified by:
shutdown
in interfaceExecutorService
- Overrides:
shutdown
in classTeamCityThreadPoolExecutor
-
shutdownNow
public List<Runnable> shutdownNow()
- Specified by:
shutdownNow
in interfaceExecutorService
- Overrides:
shutdownNow
in classThreadPoolExecutor
-
isShutdown
public boolean isShutdown()
- Specified by:
isShutdown
in interfaceExecutorService
- Overrides:
isShutdown
in classThreadPoolExecutor
-
isTerminated
public boolean isTerminated()
- Specified by:
isTerminated
in interfaceExecutorService
- Overrides:
isTerminated
in classThreadPoolExecutor
-
awaitTermination
public boolean awaitTermination(long timeout, @NotNull TimeUnit unit) throws InterruptedException
- Specified by:
awaitTermination
in interfaceExecutorService
- Overrides:
awaitTermination
in classThreadPoolExecutor
- Throws:
InterruptedException
-
-