[concurrency-interest] Questions about ThreadPoolExecutor

Brian Goetz brian at quiotix.com
Wed Mar 1 20:08:03 EST 2006


>   N = total number of threads available for execution of all batches
> 
>   Semaphore sem = new Semaphore(s);

This should be Semaphore(N);

>   Collection<Future> executeBatchCollection<Task> tasks, int nThreads) {
>     sem.aquire(nThreads);
>     try {
>         ExecutorService exec = Executors.newFixedThreadpool(nThreads);
>         Collection<Future> result = exec.invokeAll(tasks);

probably meant to return the result here

>     }
>     finally {
>       exec.shutdownNow();
>       sem.release(nThreads);
>     }
>   }

might want these in separate finally blocks, might want different 
shutdown actions, but the approach is basically right -- to start a 
batch, you have to get credit for the right number of threads from the 
limited pool, and you return those credits when the batch is done.



More information about the Concurrency-interest mailing list