Package org.infinispan.executors
Class SemaphoreCompletionService<T>
- java.lang.Object
-
- org.infinispan.executors.SemaphoreCompletionService<T>
-
- All Implemented Interfaces:
java.util.concurrent.CompletionService<T>
public class SemaphoreCompletionService<T> extends java.lang.Object implements java.util.concurrent.CompletionService<T>Executes tasks in the given executor, but never has more thanmaxConcurrentTaskstasks running at the same time.- Since:
- 7.2
- Author:
- Dan Berindei
-
-
Constructor Summary
Constructors Constructor Description SemaphoreCompletionService(java.util.concurrent.Executor executor, int maxConcurrentTasks)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.util.concurrent.Future<T>backgroundTaskFinished(java.util.concurrent.Callable<T> cleanupTask)Signal that a task that calledcontinueTaskInBackground()has finished and optionally execute another task on the just-freed thread.voidcancelQueuedTasks()When stopping, cancel any queued tasks.voidcontinueTaskInBackground()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.java.util.List<? extends java.util.concurrent.Future<T>>drainCompletionQueue()java.util.concurrent.Future<T>poll()java.util.concurrent.Future<T>poll(long timeout, java.util.concurrent.TimeUnit unit)java.util.concurrent.Future<T>submit(java.lang.Runnable task, T result)java.util.concurrent.Future<T>submit(java.util.concurrent.Callable<T> task)java.util.concurrent.Future<T>take()
-
-
-
Method Detail
-
drainCompletionQueue
public java.util.List<? extends java.util.concurrent.Future<T>> drainCompletionQueue()
-
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 java.util.concurrent.Future<T> backgroundTaskFinished(java.util.concurrent.Callable<T> cleanupTask)
Signal that a task that calledcontinueTaskInBackground()has finished and optionally execute another task on the just-freed thread.
-
submit
public java.util.concurrent.Future<T> submit(java.util.concurrent.Callable<T> task)
- Specified by:
submitin interfacejava.util.concurrent.CompletionService<T>
-
submit
public java.util.concurrent.Future<T> submit(java.lang.Runnable task, T result)
- Specified by:
submitin interfacejava.util.concurrent.CompletionService<T>
-
take
public java.util.concurrent.Future<T> take() throws java.lang.InterruptedException
- Specified by:
takein interfacejava.util.concurrent.CompletionService<T>- Throws:
java.lang.InterruptedException
-
poll
public java.util.concurrent.Future<T> poll()
- Specified by:
pollin interfacejava.util.concurrent.CompletionService<T>
-
-