Class ThreadPoolScheduledExecutorService

  • All Implemented Interfaces:
    java.util.concurrent.Executor, java.util.concurrent.ExecutorService, java.util.concurrent.ScheduledExecutorService

    public class ThreadPoolScheduledExecutorService
    extends java.util.concurrent.AbstractExecutorService
    implements java.util.concurrent.ScheduledExecutorService
    An implementation of ScheduledExecutorService which uses a thread pool. This class is similar to ScheduledThreadPoolExecutor but differs in the following ways: 1. The thread pool supports growing. IE: maxPoolSize and corePoolSize don't have to be the same. 2. Queued tasks are stored in a lock-free queue so that no bottlenecks can occur on submit. 3. Scheduling a task without a delay is O(1) as opposed to O(log(n)) 4. Canceling a task actually removes it from the queue and is O(n) as opposed to a no-op which leaves it in the queue or O(log(n)) when setRemoveOnCancelPolicy(true). 5. The mayInteruptIfRunning flag on cancel is ignored and assumed to be false. 6. ContinueExistingPeriodicTasksAfterShutdown and ExecuteExistingDelayedTasksAfterShutdown are always false.
    • Constructor Summary

      Constructors 
      Constructor Description
      ThreadPoolScheduledExecutorService​(int corePoolSize, java.util.concurrent.ThreadFactory threadFactory)
      Creates a fixed size thread pool (Similar to ScheduledThreadPoolExecutor).
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean awaitTermination​(long timeout, java.util.concurrent.TimeUnit unit)  
      void execute​(java.lang.Runnable command)  
      boolean isShutdown()  
      boolean isTerminated()  
      java.util.concurrent.ScheduledFuture<?> schedule​(java.lang.Runnable command, long delay, java.util.concurrent.TimeUnit unit)  
      <V> java.util.concurrent.ScheduledFuture<V> schedule​(java.util.concurrent.Callable<V> callable, long delay, java.util.concurrent.TimeUnit unit)  
      java.util.concurrent.ScheduledFuture<?> scheduleAtFixedRate​(java.lang.Runnable command, long initialDelay, long period, java.util.concurrent.TimeUnit unit)  
      java.util.concurrent.ScheduledFuture<?> scheduleWithFixedDelay​(java.lang.Runnable command, long initialDelay, long delay, java.util.concurrent.TimeUnit unit)  
      void shutdown()  
      java.util.List<java.lang.Runnable> shutdownNow()  
      java.lang.String toString()  
      • Methods inherited from class java.util.concurrent.AbstractExecutorService

        invokeAll, invokeAll, invokeAny, invokeAny, newTaskFor, newTaskFor, submit, submit, submit
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
      • Methods inherited from interface java.util.concurrent.ExecutorService

        invokeAll, invokeAll, invokeAny, invokeAny, submit, submit, submit
    • Constructor Detail

      • ThreadPoolScheduledExecutorService

        public ThreadPoolScheduledExecutorService​(int corePoolSize,
                                                  java.util.concurrent.ThreadFactory threadFactory)
        Creates a fixed size thread pool (Similar to ScheduledThreadPoolExecutor).
        Parameters:
        corePoolSize - The number of threads in the pool
        threadFactory - The factory used to create the threads.
    • Method Detail

      • shutdown

        public void shutdown()
        Specified by:
        shutdown in interface java.util.concurrent.ExecutorService
      • shutdownNow

        public java.util.List<java.lang.Runnable> shutdownNow()
        Specified by:
        shutdownNow in interface java.util.concurrent.ExecutorService
      • isShutdown

        public boolean isShutdown()
        Specified by:
        isShutdown in interface java.util.concurrent.ExecutorService
      • isTerminated

        public boolean isTerminated()
        Specified by:
        isTerminated in interface java.util.concurrent.ExecutorService
      • awaitTermination

        public boolean awaitTermination​(long timeout,
                                        java.util.concurrent.TimeUnit unit)
                                 throws java.lang.InterruptedException
        Specified by:
        awaitTermination in interface java.util.concurrent.ExecutorService
        Throws:
        java.lang.InterruptedException
      • execute

        public void execute​(java.lang.Runnable command)
        Specified by:
        execute in interface java.util.concurrent.Executor
      • schedule

        public java.util.concurrent.ScheduledFuture<?> schedule​(java.lang.Runnable command,
                                                                long delay,
                                                                java.util.concurrent.TimeUnit unit)
        Specified by:
        schedule in interface java.util.concurrent.ScheduledExecutorService
      • schedule

        public <V> java.util.concurrent.ScheduledFuture<V> schedule​(java.util.concurrent.Callable<V> callable,
                                                                    long delay,
                                                                    java.util.concurrent.TimeUnit unit)
        Specified by:
        schedule in interface java.util.concurrent.ScheduledExecutorService
      • scheduleAtFixedRate

        public java.util.concurrent.ScheduledFuture<?> scheduleAtFixedRate​(java.lang.Runnable command,
                                                                           long initialDelay,
                                                                           long period,
                                                                           java.util.concurrent.TimeUnit unit)
        Specified by:
        scheduleAtFixedRate in interface java.util.concurrent.ScheduledExecutorService
      • scheduleWithFixedDelay

        public java.util.concurrent.ScheduledFuture<?> scheduleWithFixedDelay​(java.lang.Runnable command,
                                                                              long initialDelay,
                                                                              long delay,
                                                                              java.util.concurrent.TimeUnit unit)
        Specified by:
        scheduleWithFixedDelay in interface java.util.concurrent.ScheduledExecutorService
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object