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 sizedScheduledExecutorServicewhich will reject executing tasks if the task queue is full. TheScheduledThreadPoolExecutorwhich is the default implementation of theScheduledExecutorServicehas 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 forScheduledThreadPoolExecutorto 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 sizedScheduledExecutorServicewith the given queue size as upper task limit.
-
Method Summary
-
-
-
Constructor Detail
-
SizedScheduledExecutorService
public SizedScheduledExecutorService(ScheduledThreadPoolExecutor delegate, long queueSize)
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 Detail
-
getScheduledThreadPoolExecutor
public ScheduledThreadPoolExecutor getScheduledThreadPoolExecutor()
Gets the wrappedScheduledThreadPoolExecutor
-
schedule
public <V> ScheduledFuture<V> schedule(Callable<V> task, long delay, TimeUnit timeUnit)
- Specified by:
schedulein interfaceScheduledExecutorService
-
schedule
public ScheduledFuture<?> schedule(Runnable task, long delay, TimeUnit timeUnit)
- 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
public boolean awaitTermination(long timeout, TimeUnit timeUnit) throws InterruptedException
- Specified by:
awaitTerminationin 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:
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
public boolean isShutdown()
- Specified by:
isShutdownin interfaceExecutorService
-
isTerminated
public boolean isTerminated()
- Specified by:
isTerminatedin 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:
shutdownin interfaceExecutorService
-
shutdownNow
public List<Runnable> shutdownNow()
- Specified by:
shutdownNowin interfaceExecutorService
-
submit
public <T> Future<T> submit(Callable<T> task)
- Specified by:
submitin interfaceExecutorService
-
submit
public Future<?> submit(Runnable task)
- Specified by:
submitin interfaceExecutorService
-
submit
public <T> Future<T> submit(Runnable task, T result)
- Specified by:
submitin 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
-
-