Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You can use a <a href="http://download.oracle.com/javase/6/docs/api/java/util/concurrent/CompletionService.html" rel="nofollow">ThreadPoolExecutor</a> with a pool size set to <a href="http://download.oracle.com/javase/6/docs/api/java/lang/Runtime.html#availableProcessors%28%29" rel="nofollow">Runtime.getRuntime().availableProcessors()</a> and <code>.execute()</code> it all the tasks you want to execute, then call <code>tpe.shutdown()</code> and then wait in a <code>while(!tpe.terminated()) { /* waiting for all tasks to complete */}</code> which blocks for all the submitted tasks to complete. <em>where <code>tpe</code> is a reference to your <code>ThreadPoolExecutor</code> instance.</em></p> <p>Or if it is more appropriate use an <a href="http://download.oracle.com/javase/6/docs/api/java/util/concurrent/ExecutorCompletionService.html" rel="nofollow">ExecutorCompletionService</a> A <a href="http://download.oracle.com/javase/6/docs/api/java/util/concurrent/CompletionService.html" rel="nofollow">CompletionService</a> 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.</p> <p><strong>NOTE:</strong> This solutions does not block like <code>ExecutorService.invokeAll()</code> does while waiting on all the jobs to finish. So while the <em>simplest</em> it is also the most limited as it will block the main thread of the application. Not good if you want status about what is going on, or to do other things while these jobs are running, like post processing the results or producing and incremental aggregated result.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload