* This default spawns up to 32 background thread on an as need basis. Idle
* threads are pruned after one minute.
* @return fresh ScheduledExecutorService
*/
public static ScheduledExecutorService defaultExecutor() {
ScheduledThreadPoolExecutor executor = new ScheduledThreadPoolExecutor(32, new ThreadFactory() {
private final AtomicInteger counter = new AtomicInteger();
@Override
public Thread newThread(Runnable r) {
Thread thread = new Thread(r, createName());
thread.setDaemon(true);
return thread;
}
private String createName() {
return "oak-executor-" + counter.getAndIncrement();
}
});
executor.setKeepAliveTime(1, TimeUnit.MINUTES);
executor.allowCoreThreadTimeOut(true);
return executor;
}