Currently I use a ConcurrentLinkedQueue in my worker thread (own implementation). Is it generally better to use an ExecutorService instead or does that depend on the case?
Asked
Active
Viewed 172 times
0
-
ExecutorService is better. Which type of ExecutorService or ThreadePoolExecutor depends on use case. Have a look at : http://stackoverflow.com/questions/3984076/what-are-the-advantages-of-using-an-executorservice and http://stackoverflow.com/questions/33596079/how-to-properly-use-java-executor/33596230#33596230 – Ravindra babu Apr 17 '16 at 09:27
1 Answers
2
I would say that it "generally" better to use and Executor since you have better control of how many and how threads are created and can easily pass around the same executor to different places to conserve resources. Creating your own thread guarantees the creation of the thread and will take up any resources that goes along with that. I always inject executors in places where threading in needed. But of course it depends on the situation. For you it might not make a big difference. Using an executor you also replaces the need for writing the queue and task consumption logic. You can just submit tasks onto a single thread executor and get the same functionality.

Sason Ohanian
- 795
- 5
- 16