Package org.apache.camel.util.concurrent
Class SizedScheduledExecutorService
- java.lang.Object
-
- org.apache.camel.util.concurrent.SizedScheduledExecutorService
-
- All Implemented Interfaces:
Executor
,ExecutorService
,ScheduledExecutorService
public class SizedScheduledExecutorService extends Object implements ScheduledExecutorService
A sizedScheduledExecutorService
which will reject executing tasks if the task queue is full. TheScheduledThreadPoolExecutor
which is the default implementation of theScheduledExecutorService
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 forScheduledThreadPoolExecutor
to reject executing tasks if an upper limit of the task queue has been reached.
-
-
Constructor Summary
Constructors Constructor Description SizedScheduledExecutorService(ScheduledThreadPoolExecutor delegate, long queueSize)
Creates a new sizedScheduledExecutorService
with the given queue size as upper task limit.
-
Method Summary
-
-
-
Constructor Detail
-
SizedScheduledExecutorService
public SizedScheduledExecutorService(ScheduledThreadPoolExecutor delegate, long queueSize)
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 Detail
-
getScheduledThreadPoolExecutor
public ScheduledThreadPoolExecutor getScheduledThreadPoolExecutor()
Gets the wrappedScheduledThreadPoolExecutor
-
schedule
public <V> ScheduledFuture<V> schedule(Callable<V> task, long delay, TimeUnit timeUnit)
- Specified by:
schedule
in interfaceScheduledExecutorService
-
schedule
public ScheduledFuture<?> schedule(Runnable task, long delay, TimeUnit timeUnit)
- 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
public boolean awaitTermination(long timeout, TimeUnit timeUnit) throws InterruptedException
- Specified by:
awaitTermination
in interfaceExecutorService
- Throws:
InterruptedException
-
getActiveCount
public int getActiveCount()
-
getCompletedTaskCount
public long getCompletedTaskCount()
-
getCorePoolSize
public int getCorePoolSize()
-
getKeepAliveTime
public long getKeepAliveTime(TimeUnit timeUnit)
-
getLargestPoolSize
public int getLargestPoolSize()
-
getMaximumPoolSize
public int getMaximumPoolSize()
-
getPoolSize
public int getPoolSize()
-
getRejectedExecutionHandler
public RejectedExecutionHandler getRejectedExecutionHandler()
-
getTaskCount
public long getTaskCount()
-
getThreadFactory
public ThreadFactory 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
public boolean isShutdown()
- Specified by:
isShutdown
in interfaceExecutorService
-
isTerminated
public boolean isTerminated()
- Specified by:
isTerminated
in interfaceExecutorService
-
isTerminating
public boolean isTerminating()
-
prestartAllCoreThreads
public int prestartAllCoreThreads()
-
prestartCoreThread
public boolean prestartCoreThread()
-
purge
public void purge()
-
setCorePoolSize
public void setCorePoolSize(int corePoolSize)
-
setKeepAliveTime
public void setKeepAliveTime(long keepAliveTime, TimeUnit timeUnit)
-
setMaximumPoolSize
public void setMaximumPoolSize(int maximumPoolSize)
-
setRejectedExecutionHandler
public void setRejectedExecutionHandler(RejectedExecutionHandler rejectedExecutionHandler)
-
setThreadFactory
public void setThreadFactory(ThreadFactory threadFactory)
-
shutdown
public void shutdown()
- Specified by:
shutdown
in interfaceExecutorService
-
shutdownNow
public List<Runnable> shutdownNow()
- Specified by:
shutdownNow
in interfaceExecutorService
-
submit
public <T> Future<T> submit(Callable<T> task)
- Specified by:
submit
in interfaceExecutorService
-
submit
public Future<?> submit(Runnable task)
- Specified by:
submit
in interfaceExecutorService
-
submit
public <T> Future<T> submit(Runnable task, T result)
- Specified by:
submit
in interfaceExecutorService
-
allowCoreThreadTimeOut
public void allowCoreThreadTimeOut(boolean value)
-
allowsCoreThreadTimeOut
public boolean allowsCoreThreadTimeOut()
-
canScheduleOrExecute
protected boolean canScheduleOrExecute()
Can the task be scheduled or executed?- Returns:
- true to accept, false to not accept
-
-