Package org.infinispan.executors
Class SemaphoreCompletionService<T>
- java.lang.Object
-
- org.infinispan.executors.SemaphoreCompletionService<T>
-
- All Implemented Interfaces:
CompletionService<T>
public class SemaphoreCompletionService<T> extends Object implements CompletionService<T>
Executes tasks in the given executor, but never has more thanmaxConcurrentTasks
tasks running at the same time.- Since:
- 7.2
- Author:
- Dan Berindei
-
-
Constructor Summary
Constructors Constructor Description SemaphoreCompletionService(Executor executor, int maxConcurrentTasks)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Future<T>
backgroundTaskFinished(Callable<T> cleanupTask)
Signal that a task that calledcontinueTaskInBackground()
has finished and optionally execute another task on the just-freed thread.void
cancelQueuedTasks()
When stopping, cancel any queued tasks.void
continueTaskInBackground()
Called from a task to remove the permit that would otherwise be freed when the task finishes running When the asynchronous part of the task finishes, it must callbackgroundTaskFinished(Callable)
to make the permit available again.List<? extends Future<T>>
drainCompletionQueue()
Future<T>
poll()
Future<T>
poll(long timeout, TimeUnit unit)
Future<T>
submit(Runnable task, T result)
Future<T>
submit(Callable<T> task)
Future<T>
take()
-
-
-
Constructor Detail
-
SemaphoreCompletionService
public SemaphoreCompletionService(Executor executor, int maxConcurrentTasks)
-
-
Method Detail
-
cancelQueuedTasks
public void cancelQueuedTasks()
When stopping, cancel any queued tasks.
-
continueTaskInBackground
public void continueTaskInBackground()
Called from a task to remove the permit that would otherwise be freed when the task finishes running When the asynchronous part of the task finishes, it must callbackgroundTaskFinished(Callable)
to make the permit available again.
-
backgroundTaskFinished
public Future<T> backgroundTaskFinished(Callable<T> cleanupTask)
Signal that a task that calledcontinueTaskInBackground()
has finished and optionally execute another task on the just-freed thread.
-
submit
public Future<T> submit(Callable<T> task)
- Specified by:
submit
in interfaceCompletionService<T>
-
submit
public Future<T> submit(Runnable task, T result)
- Specified by:
submit
in interfaceCompletionService<T>
-
take
public Future<T> take() throws InterruptedException
- Specified by:
take
in interfaceCompletionService<T>
- Throws:
InterruptedException
-
poll
public Future<T> poll()
- Specified by:
poll
in interfaceCompletionService<T>
-
poll
public Future<T> poll(long timeout, TimeUnit unit) throws InterruptedException
- Specified by:
poll
in interfaceCompletionService<T>
- Throws:
InterruptedException
-
-