Executors
provides newCachedThreadPool()
and newScheduledThreadPool()
, but not newCachedScheduledThreadPool()
, what gives
Like skaffman says, Executors
is only a collection of factory method. if you need a particular instance, you can always check all existing Executor
implementors. In your case, i think that calling one of the various constructors of ScheduledThreadPoolExecutor would be a good idea.
By design the ScheduledThreadPoolExecutor is a fixed size. You can use a single threaded version that submits to a normal ExecutorService for performing the task. This event thread + worker pool is fairly ease to coordinate and the flexibility makes up for the dedicated thread. I've used this in the past to replace TimerTasks and other non-critical tasks to utilize a common executor as a system-wide pool.
Suggested here Why does ScheduledThreadPoolExecutor only accept a fixed number of threads? workaround:
scheduledExecutor = new ScheduledThreadPoolExecutor(128); //no more than 128 threads
scheduledExecutor.setKeepAliveTime(10, TimeUnit.SECONDS);
scheduledExecutor.allowCoreThreadTimeOut(true);
java.util.concurrent.Executors
is nothing more than a collection of static convenience methods that construct common arrangements of executors.
If you want something specific that isn't offered by Executors
, then feel free to construct your own instance of the implemention classes, using the examples in Executors
as a guide.