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.
I’ve got a collection of records to process, and the processing can be parallelized,
Share
To answer your question: no, two
ExecutorServiceobjects cannot share a thread pool. However you can share anExecutorServicebetween your objects, or alternatively create several Executors, as necessary, though this is less recommended.Best solution: share the
Executorbetween your objects.