Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible for two ExecutorServices to share a thread pool?

I've got a collection of records to process, and the processing can be parallelized, so I've created an ExecutorService (via Executors#newCachedThreadPool()). The processing of an individual record is, itself, composed of parallelizable steps, so I'd like to use another ExecutorService. Is there an easy way to make this new one use the same underlying thread pool? Is it even desirable? Thanks.

like image 893
Hank Gay Avatar asked Dec 15 '08 14:12

Hank Gay


1 Answers

To answer your question: no, two ExecutorService objects cannot share a thread pool. However you can share an ExecutorService between your objects, or alternatively create several Executors, as necessary, though this is less recommended.

Best solution: share the Executor between your objects.

like image 142
Yuval Adam Avatar answered Nov 10 '22 17:11

Yuval Adam