use of java.util.concurrent.ScheduledThreadPoolExecutor in project HikariCP by brettwooldridge.
the class HikariPool method initializeHouseKeepingExecutorService.
/**
* Create/initialize the Housekeeping service {@link ScheduledExecutorService}. If the user specified an Executor
* to be used in the {@link HikariConfig}, then we use that. If no Executor was specified (typical), then create
* an Executor and configure it.
*
* @return either the user specified {@link ScheduledExecutorService}, or the one we created
*/
private ScheduledExecutorService initializeHouseKeepingExecutorService() {
if (config.getScheduledExecutor() == null) {
final ThreadFactory threadFactory = Optional.ofNullable(config.getThreadFactory()).orElse(new DefaultThreadFactory(poolName + " housekeeper", true));
final ScheduledThreadPoolExecutor executor = new ScheduledThreadPoolExecutor(1, threadFactory, new ThreadPoolExecutor.DiscardPolicy());
executor.setExecuteExistingDelayedTasksAfterShutdownPolicy(false);
executor.setRemoveOnCancelPolicy(true);
return executor;
} else {
return config.getScheduledExecutor();
}
}
use of java.util.concurrent.ScheduledThreadPoolExecutor in project elasticsearch-jdbc by jprante.
the class JDBCImporter method schedule.
private List<Future> schedule(Settings settings) {
List<Future> futures = new LinkedList<>();
if (threadPoolExecutor != null) {
logger.info("already scheduled");
return futures;
}
String[] schedule = settings.getAsArray("schedule");
Long seconds = settings.getAsTime("interval", TimeValue.timeValueSeconds(0)).seconds();
if (schedule != null && schedule.length > 0) {
Thread thread = new Thread(this);
CronThreadPoolExecutor cronThreadPoolExecutor = new CronThreadPoolExecutor(settings.getAsInt("threadpoolsize", 1));
for (String cron : schedule) {
futures.add(cronThreadPoolExecutor.schedule(thread, new CronExpression(cron)));
}
this.threadPoolExecutor = cronThreadPoolExecutor;
logger.info("scheduled with cron expressions {}", Arrays.asList(schedule));
} else if (seconds > 0L) {
Thread thread = new Thread(this);
ScheduledThreadPoolExecutor scheduledThreadPoolExecutor = new ScheduledThreadPoolExecutor(settings.getAsInt("threadpoolsize", 1));
futures.add(scheduledThreadPoolExecutor.scheduleAtFixedRate(thread, 0L, seconds, TimeUnit.SECONDS));
this.threadPoolExecutor = scheduledThreadPoolExecutor;
logger.info("scheduled at fixed rate of {} seconds", seconds);
}
return futures;
}
use of java.util.concurrent.ScheduledThreadPoolExecutor in project jersey by jersey.
the class RxListenableFutureTest method setUp.
@Before
public void setUp() throws Exception {
client = ClientBuilder.newClient().register(TerminalClientRequestFilter.class);
executor = new ScheduledThreadPoolExecutor(1, new ThreadFactoryBuilder().setNameFormat("jersey-rx-client-test-%d").setUncaughtExceptionHandler(new JerseyProcessingUncaughtExceptionHandler()).build());
}
use of java.util.concurrent.ScheduledThreadPoolExecutor in project jersey by jersey.
the class RxFlowableTest method setUp.
@Before
public void setUp() throws Exception {
client = ClientBuilder.newClient().register(TerminalClientRequestFilter.class);
client.register(RxFlowableInvokerProvider.class);
executor = new ScheduledThreadPoolExecutor(1, new ThreadFactoryBuilder().setNameFormat("jersey-rx-client-test-%d").setUncaughtExceptionHandler(new JerseyProcessingUncaughtExceptionHandler()).build());
}
use of java.util.concurrent.ScheduledThreadPoolExecutor in project elasticsearch-jdbc by jprante.
the class StandardContext method setSettings.
@Override
public StandardContext setSettings(Settings settings) {
this.settings = settings;
if (settings.getAsBoolean("metrics.enabled", false) && futures.isEmpty()) {
Thread thread = new MetricsThread();
ScheduledThreadPoolExecutor scheduledthreadPoolExecutor = new ScheduledThreadPoolExecutor(1);
futures.add(scheduledthreadPoolExecutor.scheduleAtFixedRate(thread, 0L, settings.getAsTime("metrics.interval", TimeValue.timeValueSeconds(30)).seconds(), TimeUnit.SECONDS));
logger.info("metrics thread started");
}
return this;
}
Aggregations