Class SRThreadPoolExecutor
- java.lang.Object
-
- java.util.concurrent.AbstractExecutorService
-
- java.util.concurrent.ThreadPoolExecutor
-
- com.sportradar.livedata.sdk.common.thread.SRThreadPoolExecutor
-
- All Implemented Interfaces:
Executor
,ExecutorService
public class SRThreadPoolExecutor extends ThreadPoolExecutor
-
-
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 SRThreadPoolExecutor(int corePoolSize, int maximumPoolSize, long keepAliveTime, TimeUnit unit, BlockingQueue<Runnable> workQueue)
Creates a newThreadPoolExecutor
with the given initial parameters and default thread factory and rejected execution handler.SRThreadPoolExecutor(int corePoolSize, int maximumPoolSize, long keepAliveTime, TimeUnit unit, BlockingQueue<Runnable> workQueue, RejectedExecutionHandler handler)
Creates a newThreadPoolExecutor
with the given initial parameters and default thread factory.SRThreadPoolExecutor(int corePoolSize, int maximumPoolSize, long keepAliveTime, TimeUnit unit, BlockingQueue<Runnable> workQueue, ThreadFactory threadFactory)
Creates a newThreadPoolExecutor
with the given initial parameters and default rejected execution handler.SRThreadPoolExecutor(int corePoolSize, int maximumPoolSize, long keepAliveTime, TimeUnit unit, BlockingQueue<Runnable> workQueue, ThreadFactory threadFactory, RejectedExecutionHandler handler)
Creates a newThreadPoolExecutor
with the given initial parameters.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
afterExecute(Runnable r, Throwable t)
Method invoked upon completion of execution of the given Runnable.-
Methods inherited from class java.util.concurrent.ThreadPoolExecutor
allowCoreThreadTimeOut, allowsCoreThreadTimeOut, awaitTermination, beforeExecute, execute, finalize, getActiveCount, 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
-
SRThreadPoolExecutor
public SRThreadPoolExecutor(int corePoolSize, int maximumPoolSize, long keepAliveTime, TimeUnit unit, BlockingQueue<Runnable> workQueue)
Creates a newThreadPoolExecutor
with the given initial parameters and default thread factory and rejected execution handler. It may be more convenient to use one of theExecutors
factory methods instead of this general purpose constructor.- Parameters:
corePoolSize
- the number of threads to keep in the pool, even if they are idle, unlessallowCoreThreadTimeOut
is setmaximumPoolSize
- the maximum number of threads to allow in the poolkeepAliveTime
- when the number of threads is greater than the core, this is the maximum time that excess idle threads will wait for new tasks before terminating.unit
- the time unit for thekeepAliveTime
argumentworkQueue
- the queue to use for holding tasks before they are executed. This queue will hold only theRunnable
tasks submitted by theexecute
method.- Throws:
IllegalArgumentException
- if one of the following holds:
corePoolSize < 0
keepAliveTime < 0
maximumPoolSize <= 0
maximumPoolSize < corePoolSize
NullPointerException
- ifworkQueue
is null
-
SRThreadPoolExecutor
public SRThreadPoolExecutor(int corePoolSize, int maximumPoolSize, long keepAliveTime, TimeUnit unit, BlockingQueue<Runnable> workQueue, RejectedExecutionHandler handler)
Creates a newThreadPoolExecutor
with the given initial parameters and default thread factory.- Parameters:
corePoolSize
- the number of threads to keep in the pool, even if they are idle, unlessallowCoreThreadTimeOut
is setmaximumPoolSize
- the maximum number of threads to allow in the poolkeepAliveTime
- when the number of threads is greater than the core, this is the maximum time that excess idle threads will wait for new tasks before terminating.unit
- the time unit for thekeepAliveTime
argumentworkQueue
- the queue to use for holding tasks before they are executed. This queue will hold only theRunnable
tasks submitted by theexecute
method.handler
- the handler to use when execution is blocked because the thread bounds and queue capacities are reached- Throws:
IllegalArgumentException
- if one of the following holds:
corePoolSize < 0
keepAliveTime < 0
maximumPoolSize <= 0
maximumPoolSize < corePoolSize
NullPointerException
- ifworkQueue
orhandler
is null
-
SRThreadPoolExecutor
public SRThreadPoolExecutor(int corePoolSize, int maximumPoolSize, long keepAliveTime, TimeUnit unit, BlockingQueue<Runnable> workQueue, ThreadFactory threadFactory)
Creates a newThreadPoolExecutor
with the given initial parameters and default rejected execution handler.- Parameters:
corePoolSize
- the number of threads to keep in the pool, even if they are idle, unlessallowCoreThreadTimeOut
is setmaximumPoolSize
- the maximum number of threads to allow in the poolkeepAliveTime
- when the number of threads is greater than the core, this is the maximum time that excess idle threads will wait for new tasks before terminating.unit
- the time unit for thekeepAliveTime
argumentworkQueue
- the queue to use for holding tasks before they are executed. This queue will hold only theRunnable
tasks submitted by theexecute
method.threadFactory
- the factory to use when the executor creates a new thread- Throws:
IllegalArgumentException
- if one of the following holds:
corePoolSize < 0
keepAliveTime < 0
maximumPoolSize <= 0
maximumPoolSize < corePoolSize
NullPointerException
- ifworkQueue
orthreadFactory
is null
-
SRThreadPoolExecutor
public SRThreadPoolExecutor(int corePoolSize, int maximumPoolSize, long keepAliveTime, TimeUnit unit, BlockingQueue<Runnable> workQueue, ThreadFactory threadFactory, RejectedExecutionHandler handler)
Creates a newThreadPoolExecutor
with the given initial parameters.- Parameters:
corePoolSize
- the number of threads to keep in the pool, even if they are idle, unlessallowCoreThreadTimeOut
is setmaximumPoolSize
- the maximum number of threads to allow in the poolkeepAliveTime
- when the number of threads is greater than the core, this is the maximum time that excess idle threads will wait for new tasks before terminating.unit
- the time unit for thekeepAliveTime
argumentworkQueue
- the queue to use for holding tasks before they are executed. This queue will hold only theRunnable
tasks submitted by theexecute
method.threadFactory
- the factory to use when the executor creates a new threadhandler
- the handler to use when execution is blocked because the thread bounds and queue capacities are reached- Throws:
IllegalArgumentException
- if one of the following holds:
corePoolSize < 0
keepAliveTime < 0
maximumPoolSize <= 0
maximumPoolSize < corePoolSize
NullPointerException
- ifworkQueue
orthreadFactory
orhandler
is null
-
-
Method Detail
-
afterExecute
protected void afterExecute(Runnable r, Throwable t)
Method invoked upon completion of execution of the given Runnable. This method is invoked by the thread that executed the task. If non-null, the Throwable is the uncaught
RuntimeException
orError
that caused execution to terminate abruptly.This implementation does nothing, but may be customized in subclasses. Note: To properly nest multiple overridings, subclasses should generally invoke
super.afterExecute
at the beginning of this method.Note: When actions are enclosed in tasks (such as
FutureTask
) either explicitly or via methods such assubmit
, these task objects catch and maintain computational exceptions, and so they do not cause abrupt termination, and the internal exceptions are not passed to this method. If you would like to trap both kinds of failures in this method, you can further probe for such cases, as in this sample subclass that prints either the direct cause or the underlying exception if a task has been aborted:class ExtendedExecutor extends ThreadPoolExecutor { // ... protected void afterExecute(Runnable r, Throwable t) { super.afterExecute(r, t); if (t == null && r instanceof Future<?>) { try { Object result = ((Future<?>) r).get(); } catch (CancellationException ce) { t = ce; } catch (ExecutionException ee) { t = ee.getCause(); } catch (InterruptedException ie) { Thread.currentThread().interrupt(); // ignore/reset } } if (t != null) System.out.println(t); } }
- Overrides:
afterExecute
in classThreadPoolExecutor
- Parameters:
r
- the runnable that has completedt
- the exception that caused termination, or null if execution completed normally
-
-