Fixes #793 introduce new methods for scheduled executor service that

takes/returns ScheduledExecutorService interface instances.
pull/813/head
Brett Wooldridge 8 years ago
parent b932b67ddb
commit 907da6a2cc

@ -16,6 +16,10 @@
package com.zaxxer.hikari;
import static com.zaxxer.hikari.util.UtilityElf.getNullIfEmpty;
import static java.util.concurrent.TimeUnit.MINUTES;
import static java.util.concurrent.TimeUnit.SECONDS;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
@ -25,6 +29,7 @@ import java.lang.reflect.Modifier;
import java.util.Properties;
import java.util.Set;
import java.util.TreeSet;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ScheduledThreadPoolExecutor;
import java.util.concurrent.ThreadFactory;
@ -40,11 +45,6 @@ import com.codahale.metrics.health.HealthCheckRegistry;
import com.zaxxer.hikari.metrics.MetricsTrackerFactory;
import com.zaxxer.hikari.util.PropertyElf;
import static java.util.concurrent.TimeUnit.MINUTES;
import static java.util.concurrent.TimeUnit.SECONDS;
import static com.zaxxer.hikari.util.UtilityElf.getNullIfEmpty;
public class HikariConfig implements HikariConfigMXBean
{
private static final Logger LOGGER = LoggerFactory.getLogger(HikariConfig.class);
@ -90,7 +90,7 @@ public class HikariConfig implements HikariConfigMXBean
private DataSource dataSource;
private Properties dataSourceProperties;
private ThreadFactory threadFactory;
private ScheduledThreadPoolExecutor scheduledExecutor;
private ScheduledExecutorService scheduledExecutor;
private MetricsTrackerFactory metricsTrackerFactory;
private Object metricRegistry;
private Object healthCheckRegistry;
@ -718,9 +718,10 @@ public class HikariConfig implements HikariConfigMXBean
*
* @return the executor
*/
@Deprecated
public ScheduledThreadPoolExecutor getScheduledExecutorService()
{
return scheduledExecutor;
return (ScheduledThreadPoolExecutor) scheduledExecutor;
}
/**
@ -728,11 +729,32 @@ public class HikariConfig implements HikariConfigMXBean
*
* @param executor the ScheduledExecutorService
*/
@Deprecated
public void setScheduledExecutorService(ScheduledThreadPoolExecutor executor)
{
this.scheduledExecutor = executor;
}
/**
* Get the ScheduledExecutorService used for housekeeping.
*
* @return the executor
*/
public ScheduledExecutorService getScheduledExecutor()
{
return scheduledExecutor;
}
/**
* Set the ScheduledExecutorService used for housekeeping.
*
* @param executor the ScheduledExecutorService
*/
public void setScheduledExecutor(ScheduledExecutorService executor)
{
this.scheduledExecutor = executor;
}
public String getTransactionIsolation()
{
return transactionIsolationName;

@ -41,6 +41,7 @@ import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Future;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.ScheduledThreadPoolExecutor;
import java.util.concurrent.ThreadFactory;
@ -92,7 +93,7 @@ public class HikariPool extends PoolBase implements HikariPoolMXBean, IBagStateL
private final ProxyLeakTask leakTask;
private final SuspendResumeLock suspendResumeLock;
private ScheduledThreadPoolExecutor houseKeepingExecutorService;
private ScheduledExecutorService houseKeepingExecutorService;
private ScheduledFuture<?> houseKeeperTask;
/**
@ -537,20 +538,21 @@ public class HikariPool extends PoolBase implements HikariPoolMXBean, IBagStateL
private void initializeHouseKeepingExecutorService()
{
if (config.getScheduledExecutorService() == null) {
if (config.getScheduledExecutor() == null) {
final ThreadFactory threadFactory = Optional.ofNullable(config.getThreadFactory()).orElse(new DefaultThreadFactory(poolName + " housekeeper", true));
this.houseKeepingExecutorService = new ScheduledThreadPoolExecutor(1, threadFactory, new ThreadPoolExecutor.DiscardPolicy());
this.houseKeepingExecutorService.setExecuteExistingDelayedTasksAfterShutdownPolicy(false);
this.houseKeepingExecutorService.setRemoveOnCancelPolicy(true);
final ScheduledThreadPoolExecutor executor = new ScheduledThreadPoolExecutor(1, threadFactory, new ThreadPoolExecutor.DiscardPolicy());
executor.setExecuteExistingDelayedTasksAfterShutdownPolicy(false);
executor.setRemoveOnCancelPolicy(true);
this.houseKeepingExecutorService = executor;
}
else {
this.houseKeepingExecutorService = config.getScheduledExecutorService();
this.houseKeepingExecutorService = config.getScheduledExecutor();
}
}
private void destroyHouseKeepingExecutorService()
{
if (config.getScheduledExecutorService() == null) {
if (config.getScheduledExecutor() == null) {
houseKeepingExecutorService.shutdownNow();
}
}

Loading…
Cancel
Save