Is it safe to use Singleton ExecutorService

Can I use singleton ExecutorService and multiple CompletionService instances using the same thread pool?

 CompletionService<Object> collector = new ExecutorCompletionService<Object>(threadPool); 

So, there will be several threads creating such instances, as indicated above, "collector" with one singleton threadPool.

+6
source share
1 answer

Everything will be fine. Each instance of the ExecutorCompletionService maintains its own queue of completed tasks and simply uses the underlying Executor to process each task.

Tasks can influence each other in terms of efficiency if the number of completion services is large and the thread pool has an upper limit, but this will not affect the correctness of the result.

+5
source

Source: https://habr.com/ru/post/895672/


All Articles