Class PrioritySchedulerServiceWrapper
- java.lang.Object
-
- org.threadly.concurrent.wrapper.compatibility.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 forPriorityScheduler
to be a drop in replacement for anyScheduledExecutorService
(AKA theScheduledThreadPoolExecutor
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 Summary
Constructors Constructor Description PrioritySchedulerServiceWrapper(PriorityScheduler scheduler)
Constructs a new wrapper to adhere to theScheduledExecutorService
interface.PrioritySchedulerServiceWrapper(PriorityScheduler scheduler, TaskPriority taskPriority)
Constructs a new wrapper to adhere to theScheduledExecutorService
interface.
-
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 task)
<T> java.util.List<java.util.concurrent.Future<T>>
invokeAll(java.util.Collection<? extends java.util.concurrent.Callable<T>> tasks)
<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)
<T> T
invokeAny(java.util.Collection<? extends java.util.concurrent.Callable<T>> tasks)
<T> T
invokeAny(java.util.Collection<? extends java.util.concurrent.Callable<T>> tasks, long timeout, java.util.concurrent.TimeUnit unit)
boolean
isShutdown()
boolean
isTerminated()
ListenableScheduledFuture<?>
schedule(java.lang.Runnable task, long delay, java.util.concurrent.TimeUnit unit)
<V> ListenableScheduledFuture<V>
schedule(java.util.concurrent.Callable<V> callable, long delay, java.util.concurrent.TimeUnit unit)
ListenableScheduledFuture<?>
scheduleAtFixedRate(java.lang.Runnable task, long initialDelay, long period, java.util.concurrent.TimeUnit unit)
ListenableScheduledFuture<?>
scheduleWithFixedDelay(java.lang.Runnable task, long initialDelay, long delay, java.util.concurrent.TimeUnit unit)
void
shutdown()
java.util.List<java.lang.Runnable>
shutdownNow()
This call will stop the processor as quick as possible.ListenableFuture<?>
submit(java.lang.Runnable task)
<T> ListenableFuture<T>
submit(java.lang.Runnable task, T result)
<T> ListenableFuture<T>
submit(java.util.concurrent.Callable<T> task)
-
-
-
Constructor Detail
-
PrioritySchedulerServiceWrapper
public PrioritySchedulerServiceWrapper(PriorityScheduler scheduler)
Constructs a new wrapper to adhere to theScheduledExecutorService
interface.- Parameters:
scheduler
-PriorityScheduler
implementation to rely on
-
PrioritySchedulerServiceWrapper
public PrioritySchedulerServiceWrapper(PriorityScheduler scheduler, TaskPriority taskPriority)
Constructs a new wrapper to adhere to theScheduledExecutorService
interface.- Parameters:
scheduler
-PriorityScheduler
implementation to rely ontaskPriority
- 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 interfacejava.util.concurrent.ExecutorService
-
submit
public <T> ListenableFuture<T> submit(java.util.concurrent.Callable<T> task)
- Specified by:
submit
in interfacejava.util.concurrent.ExecutorService
-
submit
public <T> ListenableFuture<T> submit(java.lang.Runnable task, T result)
- Specified by:
submit
in interfacejava.util.concurrent.ExecutorService
-
submit
public ListenableFuture<?> submit(java.lang.Runnable task)
- Specified by:
submit
in interfacejava.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 interfacejava.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 interfacejava.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 interfacejava.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 interfacejava.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 interfacejava.util.concurrent.Executor
-
schedule
public ListenableScheduledFuture<?> schedule(java.lang.Runnable task, long delay, java.util.concurrent.TimeUnit unit)
- Specified by:
schedule
in interfacejava.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 interfacejava.util.concurrent.ScheduledExecutorService
-
scheduleWithFixedDelay
public ListenableScheduledFuture<?> scheduleWithFixedDelay(java.lang.Runnable task, long initialDelay, long delay, java.util.concurrent.TimeUnit unit)
- Specified by:
scheduleWithFixedDelay
in interfacejava.util.concurrent.ScheduledExecutorService
-
scheduleAtFixedRate
public ListenableScheduledFuture<?> scheduleAtFixedRate(java.lang.Runnable task, long initialDelay, long period, java.util.concurrent.TimeUnit unit)
- Specified by:
scheduleAtFixedRate
in interfacejava.util.concurrent.ScheduledExecutorService
-
-