Multiple newSingleThreadExecutor vs. newFixedThreadPool of ExecutorService
Given each task is a infinite loop, what I would used is a
newCachedThreadPool();
This would create a thread for every task which needed it (and no more)
The benefit of using a single threaded pool each is you could shutdown the pool individually, or give each thread a name, but if you don't need this, it's just overhead.
Note: you can change the name of a thread with setName("My task") which might be useful for debugging/profiling purposes.
One of the tricks of using an ExecutorService is that it captures any uncaught exception/errors and places it in the Future
object returned. Often this Future
is discarded which means that if your task dies unexpectedly it might also do it silently.
I suggest you do a try/catch(Throwable) outside the loop and log it so you can see if the thread ever dies unexpectedly. e.g OutOfMemoryError