public class SizedScheduledExecutorService extends Object implements ScheduledExecutorService
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 and Description |
---|
SizedScheduledExecutorService(ScheduledThreadPoolExecutor delegate,
long queueSize)
Creates a new sized
ScheduledExecutorService with the given queue size as upper task limit. |
public SizedScheduledExecutorService(ScheduledThreadPoolExecutor delegate, long queueSize)
ScheduledExecutorService
with the given queue size as upper task limit.delegate
- the delegate of the actual thread pool implementationqueueSize
- the upper queue size, use 0 or negative value for unlimitedpublic ScheduledThreadPoolExecutor getScheduledThreadPoolExecutor()
ScheduledThreadPoolExecutor
public <V> ScheduledFuture<V> schedule(Callable<V> task, long delay, TimeUnit timeUnit)
schedule
in interface ScheduledExecutorService
public ScheduledFuture<?> schedule(Runnable task, long delay, TimeUnit timeUnit)
schedule
in interface ScheduledExecutorService
public ScheduledFuture<?> scheduleAtFixedRate(Runnable task, long initialDelay, long period, TimeUnit timeUnit)
scheduleAtFixedRate
in interface ScheduledExecutorService
public ScheduledFuture<?> scheduleWithFixedDelay(Runnable task, long initialDelay, long period, TimeUnit timeUnit)
scheduleWithFixedDelay
in interface ScheduledExecutorService
public boolean awaitTermination(long timeout, TimeUnit timeUnit) throws InterruptedException
awaitTermination
in interface ExecutorService
InterruptedException
public int getActiveCount()
public long getCompletedTaskCount()
public int getCorePoolSize()
public long getKeepAliveTime(TimeUnit timeUnit)
public int getLargestPoolSize()
public int getMaximumPoolSize()
public int getPoolSize()
public RejectedExecutionHandler getRejectedExecutionHandler()
public long getTaskCount()
public ThreadFactory getThreadFactory()
public <T> List<Future<T>> invokeAll(Collection<? extends Callable<T>> tasks) throws InterruptedException
invokeAll
in interface ExecutorService
InterruptedException
public <T> List<Future<T>> invokeAll(Collection<? extends Callable<T>> tasks, long timeout, TimeUnit timeUnit) throws InterruptedException
invokeAll
in interface ExecutorService
InterruptedException
public <T> T invokeAny(Collection<? extends Callable<T>> tasks) throws InterruptedException, ExecutionException
invokeAny
in interface ExecutorService
InterruptedException
ExecutionException
public <T> T invokeAny(Collection<? extends Callable<T>> tasks, long timeout, TimeUnit timeUnit) throws InterruptedException, ExecutionException, TimeoutException
invokeAny
in interface ExecutorService
InterruptedException
ExecutionException
TimeoutException
public boolean isShutdown()
isShutdown
in interface ExecutorService
public boolean isTerminated()
isTerminated
in interface ExecutorService
public boolean isTerminating()
public int prestartAllCoreThreads()
public boolean prestartCoreThread()
public void purge()
public void setCorePoolSize(int corePoolSize)
public void setKeepAliveTime(long keepAliveTime, TimeUnit timeUnit)
public void setMaximumPoolSize(int maximumPoolSize)
public void setRejectedExecutionHandler(RejectedExecutionHandler rejectedExecutionHandler)
public void setThreadFactory(ThreadFactory threadFactory)
public void shutdown()
shutdown
in interface ExecutorService
public List<Runnable> shutdownNow()
shutdownNow
in interface ExecutorService
public <T> Future<T> submit(Callable<T> task)
submit
in interface ExecutorService
public Future<?> submit(Runnable task)
submit
in interface ExecutorService
public <T> Future<T> submit(Runnable task, T result)
submit
in interface ExecutorService
public void allowCoreThreadTimeOut(boolean value)
public boolean allowsCoreThreadTimeOut()
protected boolean canScheduleOrExecute()
Apache Camel