Class PrioritySchedulerServiceWrapper

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

    public class PrioritySchedulerServiceWrapper
    extends java.lang.Object
    This is a wrapper for PriorityScheduler 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 1.0.0 as org.threadly.concurrent.PriorityScheduledExecutorServiceWrapper)
    • Constructor Detail

      • PrioritySchedulerServiceWrapper

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

        public PrioritySchedulerServiceWrapper​(PriorityScheduler scheduler,
                                               TaskPriority taskPriority)
        Constructs a new wrapper to adhere to the ScheduledExecutorService interface.
        Parameters:
        scheduler - PriorityScheduler 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()
        This call will stop the processor as quick as possible. Any tasks which are awaiting execution will be canceled and returned as a result to this call.

        Unlike ExecutorService implementation there is no attempt to stop any currently execution tasks.

        This method does not wait for actively executing tasks toterminate. Use awaitTermination to do that.

        Returns:
        list of tasks that never commenced execution
      • 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