Package org.apache.camel.util.concurrent
Class SizedScheduledExecutorService
java.lang.Object
org.apache.camel.util.concurrent.SizedScheduledExecutorService
- All Implemented Interfaces:
Executor
,ExecutorService
,ScheduledExecutorService
A sized
ScheduledExecutorService
which will reject executing tasks if the task queue is full.
The ScheduledThreadPoolExecutor
which is the default implementation of the ScheduledExecutorService
has unbounded task queue, which mean you can keep scheduling tasks which may cause the system to run out of memory.
This class is a wrapped for ScheduledThreadPoolExecutor
to reject executing tasks if an upper limit of the
task queue has been reached.-
Constructor Summary
ConstructorDescriptionSizedScheduledExecutorService
(ScheduledThreadPoolExecutor delegate, long queueSize) Creates a new sizedScheduledExecutorService
with the given queue size as upper task limit. -
Method Summary
Modifier and TypeMethodDescriptionvoid
allowCoreThreadTimeOut
(boolean value) boolean
boolean
awaitTermination
(long timeout, TimeUnit timeUnit) protected boolean
Can the task be scheduled or executed?void
int
long
int
long
getKeepAliveTime
(TimeUnit timeUnit) int
int
int
Gets the wrappedScheduledThreadPoolExecutor
long
invokeAll
(Collection<? extends Callable<T>> tasks) invokeAll
(Collection<? extends Callable<T>> tasks, long timeout, TimeUnit timeUnit) <T> T
invokeAny
(Collection<? extends Callable<T>> tasks) <T> T
invokeAny
(Collection<? extends Callable<T>> tasks, long timeout, TimeUnit timeUnit) boolean
boolean
boolean
int
boolean
void
purge()
<V> ScheduledFuture<V>
scheduleAtFixedRate
(Runnable task, long initialDelay, long period, TimeUnit timeUnit) scheduleWithFixedDelay
(Runnable task, long initialDelay, long period, TimeUnit timeUnit) void
setCorePoolSize
(int corePoolSize) void
setKeepAliveTime
(long keepAliveTime, TimeUnit timeUnit) void
setMaximumPoolSize
(int maximumPoolSize) void
setRejectedExecutionHandler
(RejectedExecutionHandler rejectedExecutionHandler) void
setThreadFactory
(ThreadFactory threadFactory) void
shutdown()
Future<?>
<T> Future<T>
<T> Future<T>
toString()
-
Constructor Details
-
SizedScheduledExecutorService
Creates a new sizedScheduledExecutorService
with the given queue size as upper task limit.- Parameters:
delegate
- the delegate of the actual thread pool implementationqueueSize
- the upper queue size, use 0 or negative value for unlimited
-
-
Method Details
-
getScheduledThreadPoolExecutor
Gets the wrappedScheduledThreadPoolExecutor
-
schedule
- Specified by:
schedule
in interfaceScheduledExecutorService
-
schedule
- Specified by:
schedule
in interfaceScheduledExecutorService
-
scheduleAtFixedRate
public ScheduledFuture<?> scheduleAtFixedRate(Runnable task, long initialDelay, long period, TimeUnit timeUnit) - Specified by:
scheduleAtFixedRate
in interfaceScheduledExecutorService
-
scheduleWithFixedDelay
public ScheduledFuture<?> scheduleWithFixedDelay(Runnable task, long initialDelay, long period, TimeUnit timeUnit) - Specified by:
scheduleWithFixedDelay
in interfaceScheduledExecutorService
-
awaitTermination
- Specified by:
awaitTermination
in interfaceExecutorService
- Throws:
InterruptedException
-
getActiveCount
-
getCompletedTaskCount
-
getCorePoolSize
-
getKeepAliveTime
-
getLargestPoolSize
-
getMaximumPoolSize
-
getPoolSize
-
getRejectedExecutionHandler
-
getTaskCount
-
getThreadFactory
-
invokeAll
public <T> List<Future<T>> invokeAll(Collection<? extends Callable<T>> tasks) throws InterruptedException - Specified by:
invokeAll
in interfaceExecutorService
- Throws:
InterruptedException
-
invokeAll
public <T> List<Future<T>> invokeAll(Collection<? extends Callable<T>> tasks, long timeout, TimeUnit timeUnit) throws InterruptedException - Specified by:
invokeAll
in interfaceExecutorService
- Throws:
InterruptedException
-
invokeAny
public <T> T invokeAny(Collection<? extends Callable<T>> tasks) throws InterruptedException, ExecutionException - Specified by:
invokeAny
in interfaceExecutorService
- Throws:
InterruptedException
ExecutionException
-
invokeAny
public <T> T invokeAny(Collection<? extends Callable<T>> tasks, long timeout, TimeUnit timeUnit) throws InterruptedException, ExecutionException, TimeoutException - Specified by:
invokeAny
in interfaceExecutorService
- Throws:
InterruptedException
ExecutionException
TimeoutException
-
isShutdown
- Specified by:
isShutdown
in interfaceExecutorService
-
isTerminated
- Specified by:
isTerminated
in interfaceExecutorService
-
isTerminating
-
prestartAllCoreThreads
-
prestartCoreThread
-
purge
-
setCorePoolSize
-
setKeepAliveTime
-
setMaximumPoolSize
-
setRejectedExecutionHandler
-
setThreadFactory
-
shutdown
- Specified by:
shutdown
in interfaceExecutorService
-
shutdownNow
- Specified by:
shutdownNow
in interfaceExecutorService
-
submit
- Specified by:
submit
in interfaceExecutorService
-
submit
- Specified by:
submit
in interfaceExecutorService
-
submit
- Specified by:
submit
in interfaceExecutorService
-
execute
-
allowCoreThreadTimeOut
-
allowsCoreThreadTimeOut
-
canScheduleOrExecute
Can the task be scheduled or executed?- Returns:
- true to accept, false to not accept
-
toString
-