org.apache.camel.util.concurrent
Class SizedScheduledExecutorService

java.lang.Object
  extended by org.apache.camel.util.concurrent.SizedScheduledExecutorService
All Implemented Interfaces:
Executor, ExecutorService, ScheduledExecutorService

public class SizedScheduledExecutorService
extends Object
implements 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.


Constructor Summary
SizedScheduledExecutorService(ScheduledThreadPoolExecutor delegate, long queueSize)
          Creates a new sized ScheduledExecutorService with the given queue size as upper task limit.
 
Method Summary
 void allowCoreThreadTimeOut(boolean value)
           
 boolean allowsCoreThreadTimeOut()
           
 boolean awaitTermination(long timeout, TimeUnit timeUnit)
           
protected  boolean canScheduleOrExecute()
          Can the task be scheduled or executed?
 void execute(Runnable task)
           
 int getActiveCount()
           
 long getCompletedTaskCount()
           
 int getCorePoolSize()
           
 long getKeepAliveTime(TimeUnit timeUnit)
           
 int getLargestPoolSize()
           
 int getMaximumPoolSize()
           
 int getPoolSize()
           
 RejectedExecutionHandler getRejectedExecutionHandler()
           
 ScheduledThreadPoolExecutor getScheduledThreadPoolExecutor()
          Gets the wrapped ScheduledThreadPoolExecutor
 long getTaskCount()
           
 ThreadFactory getThreadFactory()
           
<T> List<Future<T>>
invokeAll(Collection<? extends Callable<T>> tasks)
           
<T> List<Future<T>>
invokeAll(Collection<? extends Callable<T>> tasks, long timeout, TimeUnit timeUnit)
           
<T> T
invokeAny(Collection<? extends Callable<T>> tasks)
           
<T> T
invokeAny(Collection<? extends Callable<T>> tasks, long timeout, TimeUnit timeUnit)
           
 boolean isShutdown()
           
 boolean isTerminated()
           
 boolean isTerminating()
           
 int prestartAllCoreThreads()
           
 boolean prestartCoreThread()
           
 void purge()
           
<V> ScheduledFuture<V>
schedule(Callable<V> task, long delay, TimeUnit timeUnit)
           
 ScheduledFuture<?> schedule(Runnable task, long delay, TimeUnit timeUnit)
           
 ScheduledFuture<?> scheduleAtFixedRate(Runnable task, long initialDelay, long period, TimeUnit timeUnit)
           
 ScheduledFuture<?> scheduleWithFixedDelay(Runnable task, long initialDelay, long period, TimeUnit timeUnit)
           
 void setCorePoolSize(int corePoolSize)
           
 void setKeepAliveTime(long keepAliveTime, TimeUnit timeUnit)
           
 void setMaximumPoolSize(int maximumPoolSize)
           
 void setRejectedExecutionHandler(RejectedExecutionHandler rejectedExecutionHandler)
           
 void setThreadFactory(ThreadFactory threadFactory)
           
 void shutdown()
           
 List<Runnable> shutdownNow()
           
<T> Future<T>
submit(Callable<T> task)
           
 Future<?> submit(Runnable task)
           
<T> Future<T>
submit(Runnable task, T result)
           
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

SizedScheduledExecutorService

public SizedScheduledExecutorService(ScheduledThreadPoolExecutor delegate,
                                     long queueSize)
Creates a new sized ScheduledExecutorService with the given queue size as upper task limit.

Parameters:
delegate - the delegate of the actual thread pool implementation
queueSize - the upper queue size, use 0 or negative value for unlimited
Method Detail

getScheduledThreadPoolExecutor

public ScheduledThreadPoolExecutor getScheduledThreadPoolExecutor()
Gets the wrapped ScheduledThreadPoolExecutor


schedule

public <V> ScheduledFuture<V> schedule(Callable<V> task,
                                       long delay,
                                       TimeUnit timeUnit)
Specified by:
schedule in interface ScheduledExecutorService

schedule

public ScheduledFuture<?> schedule(Runnable task,
                                   long delay,
                                   TimeUnit timeUnit)
Specified by:
schedule in interface ScheduledExecutorService

scheduleAtFixedRate

public ScheduledFuture<?> scheduleAtFixedRate(Runnable task,
                                              long initialDelay,
                                              long period,
                                              TimeUnit timeUnit)
Specified by:
scheduleAtFixedRate in interface ScheduledExecutorService

scheduleWithFixedDelay

public ScheduledFuture<?> scheduleWithFixedDelay(Runnable task,
                                                 long initialDelay,
                                                 long period,
                                                 TimeUnit timeUnit)
Specified by:
scheduleWithFixedDelay in interface ScheduledExecutorService

awaitTermination

public boolean awaitTermination(long timeout,
                                TimeUnit timeUnit)
                         throws InterruptedException
Specified by:
awaitTermination in interface ExecutorService
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 interface ExecutorService
Throws:
InterruptedException

invokeAll

public <T> List<Future<T>> invokeAll(Collection<? extends Callable<T>> tasks,
                                     long timeout,
                                     TimeUnit timeUnit)
                          throws InterruptedException
Specified by:
invokeAll in interface ExecutorService
Throws:
InterruptedException

invokeAny

public <T> T invokeAny(Collection<? extends Callable<T>> tasks)
            throws InterruptedException,
                   ExecutionException
Specified by:
invokeAny in interface ExecutorService
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 interface ExecutorService
Throws:
InterruptedException
ExecutionException
TimeoutException

isShutdown

public boolean isShutdown()
Specified by:
isShutdown in interface ExecutorService

isTerminated

public boolean isTerminated()
Specified by:
isTerminated in interface ExecutorService

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 interface ExecutorService

shutdownNow

public List<Runnable> shutdownNow()
Specified by:
shutdownNow in interface ExecutorService

submit

public <T> Future<T> submit(Callable<T> task)
Specified by:
submit in interface ExecutorService

submit

public Future<?> submit(Runnable task)
Specified by:
submit in interface ExecutorService

submit

public <T> Future<T> submit(Runnable task,
                            T result)
Specified by:
submit in interface ExecutorService

execute

public void execute(Runnable task)
Specified by:
execute in interface Executor

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

toString

public String toString()
Overrides:
toString in class Object


Apache CAMEL