java.lang.Objectjava.util.concurrent.ExecutorCompletionService<V>
public class ExecutorCompletionService<V>
A CompletionService that uses a supplied Executor
to execute tasks. This class arranges that submitted tasks are,
upon completion, placed on a queue accessible using take.
The class is lightweight enough to be suitable for transient use
when processing groups of tasks.
Usage Examples. Suppose you have a set of solvers for a certain problem, each returning a value of some type Result, and would like to run them concurrently, processing the results of each of them that return a non-null value, in some method use(Result r). You could write this as:
ecs.submit(s); int n = solvers.size(); for (int i = 0; i < n; ++i) { if (r != null) use(r); } }
int n = solvers.size(); try { futures.add(ecs.submit(s)); for (int i = 0; i < n; ++i) { try { if (r != null) { result = r; break; } } } finally { f.cancel(true); } if (result != null) use(result); }
| Constructor Summary | |
|---|---|
ExecutorCompletionService(Executor executor)
Creates an ExecutorCompletionService using the supplied executor for base task execution and a LinkedBlockingQueue as a completion queue. |
|
ExecutorCompletionService(Executor executor,
BlockingQueue<Future<V>> completionQueue)
Creates an ExecutorCompletionService using the supplied executor for base task execution and the supplied queue as its completion queue. |
|
| Method Summary | |
|---|---|
Future<V> |
poll()
Retrieves and removes the Future representing the next completed task or null if none are present. |
Future<V> |
poll(long timeout,
TimeUnit unit)
Retrieves and removes the Future representing the next completed task, waiting if necessary up to the specified wait time if none are yet present. |
Future<V> |
submit(Callable<V> task)
Submits a value-returning task for execution and returns a Future representing the pending results of the task. |
Future<V> |
submit(Runnable task,
V result)
Submits a Runnable task for execution and returns a Future representing that task.Upon completion, this task may be taken or polled. |
Future<V> |
take()
Retrieves and removes the Future representing the next completed task, waiting if none are yet present. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public ExecutorCompletionService(Executor executor)
LinkedBlockingQueue as a completion queue.
executor - the executor to use
NullPointerException - if executor is nullpublic ExecutorCompletionService(Executor executor, BlockingQueue<Future<V>> completionQueue)
executor - the executor to usecompletionQueue - the queue to use as the completion queue
normally one dedicated for use by this service
NullPointerException - if executor or completionQueue are null| Method Detail |
|---|
public Future<V> submit(Callable<V> task)
CompletionService
submit in interface CompletionService<V>task - the task to submit
public Future<V> submit(Runnable task, V result)
CompletionService
submit in interface CompletionService<V>task - the task to submitresult - the result to return upon successful completion
public Future<V> take() throws InterruptedException
CompletionService
take in interface CompletionService<V>InterruptedException - if interrupted while waiting.public Future<V> poll()
CompletionService
poll in interface CompletionService<V>public Future<V> poll(long timeout, TimeUnit unit) throws InterruptedException
CompletionService
poll in interface CompletionService<V>timeout - how long to wait before giving up, in units of
unitunit - a TimeUnit determining how to interpret the
timeout parameter
InterruptedException - if interrupted while waiting.Ces informations proviennent du site de http://java.sun.com
Le contenu de cette page provient du site de Sun, et est généré depuis un cache sur l'infobrol après certains traitements automatisés. La présentation peut donc différer du document original, mais le contenu aussi. Vous pouvez utiliser ce bouton pour afficher la page originale du site de Sun :
Maintenir les pages en cache sur différents sites peut offrir plus de disponibilité.
Chaque page est indexée dans la base de donnée, ce qui permet de retrouver facilement les informations, au moyen des sommaires, du moteur de recherche interne, etc.
Des facilités sont mises en place pour que les membres de l'infobrol puissent effectuer des traductions en français des différents documents. Ceci devrait permettre aux débutants en programmation Java de consulter les API en français s'ils maîtrisent moins bien la langue de Shakespeare. Dans le cas où une traduction a été soumise, elle est disponible au moyen d'un lien en bas de page. Si la traduction a été validée, la page s'affiche par défaut en français, et un lien en bas de page permet d'atteindre la version en anglais.
Le code sur l'infobrol est automatiquement coloré selon la syntaxe, et les différents mots clés sont transformés en liens pour accéder rapidement aux informations.
Vous avez la possibilité de partager vos expériences en proposant vos propres extraits de code en utilisant le bouton "ajouter un commentaire" en bas de page. Si vous visitez simplement l'infobrol, vous avez déjà accès à cette fonction, mais si vous étes membre du brol, vous pouvez en plus utiliser des boutons supplémentaires de mise en forme, dont la coloration automatique de vos extraits de codes.
Vous pouvez modifier vos préférences dans votre profil pour ne plus afficher les interactions avec les réseaux sociaux sur ces pages.
7 mots clés dont 0 définis manuellement (plus d'information...).
Avertissement
Cette page ne possède pas encore de mots clés manuels, ceci est donc un exemple automatique (les niveaux de pertinence sont fictifs, mais les liens sont valables). Pour tester le nuage avec une page qui contient des mots définis manuellement, vous pouvez cliquer ici.Vous pouvez modifier vos préférences dans votre profil pour ne plus afficher le nuage de mots clés.
Recherche (afficher)
Utilisateur (masquer)
Navigation (masquer)
Apparence (afficher)
Stats (afficher)
Citation (masquer)