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()
ScheduledThreadPoolExecutorpublic <V> ScheduledFuture<V> schedule(Callable<V> task, long delay, TimeUnit timeUnit)
schedule in interface ScheduledExecutorServicepublic ScheduledFuture<?> schedule(Runnable task, long delay, TimeUnit timeUnit)
schedule in interface ScheduledExecutorServicepublic ScheduledFuture<?> scheduleAtFixedRate(Runnable task, long initialDelay, long period, TimeUnit timeUnit)
scheduleAtFixedRate in interface ScheduledExecutorServicepublic ScheduledFuture<?> scheduleWithFixedDelay(Runnable task, long initialDelay, long period, TimeUnit timeUnit)
scheduleWithFixedDelay in interface ScheduledExecutorServicepublic boolean awaitTermination(long timeout,
TimeUnit timeUnit)
throws InterruptedException
awaitTermination in interface ExecutorServiceInterruptedExceptionpublic 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 ExecutorServiceInterruptedExceptionpublic <T> List<Future<T>> invokeAll(Collection<? extends Callable<T>> tasks, long timeout, TimeUnit timeUnit) throws InterruptedException
invokeAll in interface ExecutorServiceInterruptedExceptionpublic <T> T invokeAny(Collection<? extends Callable<T>> tasks) throws InterruptedException, ExecutionException
invokeAny in interface ExecutorServiceInterruptedExceptionExecutionExceptionpublic <T> T invokeAny(Collection<? extends Callable<T>> tasks, long timeout, TimeUnit timeUnit) throws InterruptedException, ExecutionException, TimeoutException
invokeAny in interface ExecutorServiceInterruptedExceptionExecutionExceptionTimeoutExceptionpublic boolean isShutdown()
isShutdown in interface ExecutorServicepublic boolean isTerminated()
isTerminated in interface ExecutorServicepublic 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 ExecutorServicepublic List<Runnable> shutdownNow()
shutdownNow in interface ExecutorServicepublic <T> Future<T> submit(Callable<T> task)
submit in interface ExecutorServicepublic Future<?> submit(Runnable task)
submit in interface ExecutorServicepublic <T> Future<T> submit(Runnable task, T result)
submit in interface ExecutorServicepublic void allowCoreThreadTimeOut(boolean value)
public boolean allowsCoreThreadTimeOut()
protected boolean canScheduleOrExecute()
Apache Camel