Wednesday, 14 August 2013

How do I reuse Threads with different ExecutorService objects?

How do I reuse Threads with different ExecutorService objects?

Is it possible to have one thread pool for my whole program so that the
threads are reused, or do I need to make the ExecutorService global/ pass
it to all objects using it.
To be more precise I have multiple tasks that run in my program but they
do not run extremely often.
ScheduledExecutorService executorService =
Executors.newScheduledThreadPool(1);
I believe that it would be unnecessary to have a full thread running all
the time for every single task but it might also be costly to restart the
thread every single time when a task is executed.
Is there a better alternative to making the Thread pool global?

No comments:

Post a Comment