Class SingleThreadSchedulerServiceWrapper

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

    public class SingleThreadSchedulerServiceWrapper
    extends java.lang.Object
    This is a wrapper for SingleThreadScheduler to be a drop in replacement for any ScheduledExecutorService (AKA the ScheduledThreadPoolExecutor interface). It does make some performance sacrifices to adhere to this interface, but those are pretty minimal. The largest compromise in here is easily scheduleAtFixedRate (which you should read the javadocs for if you need).
    Since:
    4.6.0 (since 2.0.0 at org.threadly.concurrent)
    • Constructor Detail

      • SingleThreadSchedulerServiceWrapper

        public SingleThreadSchedulerServiceWrapper​(SingleThreadScheduler scheduler)
        Constructs a new wrapper to adhere to the ScheduledExecutorService interface.
        Parameters:
        scheduler - scheduler implementation to rely on
      • SingleThreadSchedulerServiceWrapper

        public SingleThreadSchedulerServiceWrapper​(SingleThreadScheduler scheduler,
                                                   TaskPriority taskPriority)
        Constructs a new wrapper to adhere to the ScheduledExecutorService interface.
        Parameters:
        scheduler - scheduler implementation to rely on
        taskPriority - Priority for all tasks submitted to the parent scheduler
    • Method Detail

      • shutdown

        public void shutdown()
      • shutdownNow

        public java.util.List<java.lang.Runnable> shutdownNow()
      • isTerminated

        public boolean isTerminated()
      • awaitTermination

        public boolean awaitTermination​(long timeout,
                                        java.util.concurrent.TimeUnit unit)
                                 throws java.lang.InterruptedException
        Throws:
        java.lang.InterruptedException
      • isShutdown

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

        public <T> ListenableFuture<T> submit​(java.util.concurrent.Callable<T> task)
        Specified by:
        submit in interface java.util.concurrent.ExecutorService
      • submit

        public <T> ListenableFuture<T> submit​(java.lang.Runnable task,
                                              T result)
        Specified by:
        submit in interface java.util.concurrent.ExecutorService
      • submit

        public ListenableFuture<?> submit​(java.lang.Runnable task)
        Specified by:
        submit in interface java.util.concurrent.ExecutorService
      • invokeAll

        public <T> java.util.List<java.util.concurrent.Future<T>> invokeAll​(java.util.Collection<? extends java.util.concurrent.Callable<T>> tasks)
                                                                     throws java.lang.InterruptedException
        Specified by:
        invokeAll in interface java.util.concurrent.ExecutorService
        Throws:
        java.lang.InterruptedException
      • invokeAll

        public <T> java.util.List<java.util.concurrent.Future<T>> invokeAll​(java.util.Collection<? extends java.util.concurrent.Callable<T>> tasks,
                                                                            long timeout,
                                                                            java.util.concurrent.TimeUnit unit)
                                                                     throws java.lang.InterruptedException
        Specified by:
        invokeAll in interface java.util.concurrent.ExecutorService
        Throws:
        java.lang.InterruptedException
      • invokeAny

        public <T> T invokeAny​(java.util.Collection<? extends java.util.concurrent.Callable<T>> tasks)
                        throws java.lang.InterruptedException,
                               java.util.concurrent.ExecutionException
        Specified by:
        invokeAny in interface java.util.concurrent.ExecutorService
        Throws:
        java.lang.InterruptedException
        java.util.concurrent.ExecutionException
      • invokeAny

        public <T> T invokeAny​(java.util.Collection<? extends java.util.concurrent.Callable<T>> tasks,
                               long timeout,
                               java.util.concurrent.TimeUnit unit)
                        throws java.lang.InterruptedException,
                               java.util.concurrent.ExecutionException,
                               java.util.concurrent.TimeoutException
        Specified by:
        invokeAny in interface java.util.concurrent.ExecutorService
        Throws:
        java.lang.InterruptedException
        java.util.concurrent.ExecutionException
        java.util.concurrent.TimeoutException
      • execute

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

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

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

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

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