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.-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionSizedScheduledExecutorService(ScheduledThreadPoolExecutor delegate, long queueSize) Creates a new sizedScheduledExecutorServicewith the given queue size as upper task limit. -
Method Summary
Modifier and TypeMethodDescriptionvoidallowCoreThreadTimeOut(boolean value) booleanbooleanawaitTermination(long timeout, TimeUnit timeUnit) protected booleanCan the task be scheduled or executed?voidintlongintlonggetKeepAliveTime(TimeUnit timeUnit) intintintGets the wrappedScheduledThreadPoolExecutorlonginvokeAll(Collection<? extends Callable<T>> tasks) invokeAll(Collection<? extends Callable<T>> tasks, long timeout, TimeUnit timeUnit) <T> TinvokeAny(Collection<? extends Callable<T>> tasks) <T> TinvokeAny(Collection<? extends Callable<T>> tasks, long timeout, TimeUnit timeUnit) booleanbooleanbooleanintbooleanvoidpurge()<V> ScheduledFuture<V> scheduleAtFixedRate(Runnable task, long initialDelay, long period, TimeUnit timeUnit) scheduleWithFixedDelay(Runnable task, long initialDelay, long period, TimeUnit timeUnit) voidsetCorePoolSize(int corePoolSize) voidsetKeepAliveTime(long keepAliveTime, TimeUnit timeUnit) voidsetMaximumPoolSize(int maximumPoolSize) voidsetRejectedExecutionHandler(RejectedExecutionHandler rejectedExecutionHandler) voidsetThreadFactory(ThreadFactory threadFactory) voidshutdown()Future<?> <T> Future<T> <T> Future<T> toString()
-
Field Details
-
QUEUE_SIZE_LIMIT_REACHED
- See Also:
-
-
Constructor Details
-
SizedScheduledExecutorService
Creates a new sizedScheduledExecutorServicewith 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:
schedulein interfaceScheduledExecutorService
-
schedule
- Specified by:
schedulein interfaceScheduledExecutorService
-
scheduleAtFixedRate
public ScheduledFuture<?> scheduleAtFixedRate(Runnable task, long initialDelay, long period, TimeUnit timeUnit) - Specified by:
scheduleAtFixedRatein interfaceScheduledExecutorService
-
scheduleWithFixedDelay
public ScheduledFuture<?> scheduleWithFixedDelay(Runnable task, long initialDelay, long period, TimeUnit timeUnit) - Specified by:
scheduleWithFixedDelayin interfaceScheduledExecutorService
-
awaitTermination
- Specified by:
awaitTerminationin 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:
invokeAllin interfaceExecutorService- Throws:
InterruptedException
-
invokeAll
public <T> List<Future<T>> invokeAll(Collection<? extends Callable<T>> tasks, long timeout, TimeUnit timeUnit) throws InterruptedException - Specified by:
invokeAllin interfaceExecutorService- Throws:
InterruptedException
-
invokeAny
public <T> T invokeAny(Collection<? extends Callable<T>> tasks) throws InterruptedException, ExecutionException - Specified by:
invokeAnyin interfaceExecutorService- Throws:
InterruptedExceptionExecutionException
-
invokeAny
public <T> T invokeAny(Collection<? extends Callable<T>> tasks, long timeout, TimeUnit timeUnit) throws InterruptedException, ExecutionException, TimeoutException - Specified by:
invokeAnyin interfaceExecutorService- Throws:
InterruptedExceptionExecutionExceptionTimeoutException
-
isShutdown
- Specified by:
isShutdownin interfaceExecutorService
-
isTerminated
- Specified by:
isTerminatedin interfaceExecutorService
-
isTerminating
-
prestartAllCoreThreads
-
prestartCoreThread
-
purge
-
setCorePoolSize
-
setKeepAliveTime
-
setMaximumPoolSize
-
setRejectedExecutionHandler
-
setThreadFactory
-
shutdown
- Specified by:
shutdownin interfaceExecutorService
-
shutdownNow
- Specified by:
shutdownNowin interfaceExecutorService
-
submit
- Specified by:
submitin interfaceExecutorService
-
submit
- Specified by:
submitin interfaceExecutorService
-
submit
- Specified by:
submitin interfaceExecutorService
-
execute
-
allowCoreThreadTimeOut
-
allowsCoreThreadTimeOut
-
canScheduleOrExecute
Can the task be scheduled or executed?- Returns:
- true to accept, false to not accept
-
toString
-