|
|
|
@ -13,6 +13,9 @@ import java.sql.SQLException;
|
|
|
|
|
import java.sql.Statement;
|
|
|
|
|
import java.util.Properties;
|
|
|
|
|
import java.util.concurrent.Executor;
|
|
|
|
|
import java.util.concurrent.Executors;
|
|
|
|
|
import java.util.concurrent.ThreadFactory;
|
|
|
|
|
import java.util.concurrent.ThreadPoolExecutor;
|
|
|
|
|
import java.util.concurrent.TimeUnit;
|
|
|
|
|
import java.util.concurrent.atomic.AtomicReference;
|
|
|
|
|
|
|
|
|
@ -29,6 +32,7 @@ import com.zaxxer.hikari.util.ClockSource;
|
|
|
|
|
import com.zaxxer.hikari.util.DriverDataSource;
|
|
|
|
|
import com.zaxxer.hikari.util.PropertyElf;
|
|
|
|
|
import com.zaxxer.hikari.util.UtilityElf;
|
|
|
|
|
import com.zaxxer.hikari.util.UtilityElf.DefaultThreadFactory;
|
|
|
|
|
|
|
|
|
|
abstract class PoolBase
|
|
|
|
|
{
|
|
|
|
@ -47,6 +51,7 @@ abstract class PoolBase
|
|
|
|
|
private int transactionIsolation;
|
|
|
|
|
private int isNetworkTimeoutSupported;
|
|
|
|
|
private int isQueryTimeoutSupported;
|
|
|
|
|
private Executor netTimeoutExecutor;
|
|
|
|
|
private DataSource dataSource;
|
|
|
|
|
|
|
|
|
|
private final String catalog;
|
|
|
|
@ -55,7 +60,6 @@ abstract class PoolBase
|
|
|
|
|
private final boolean isUseJdbc4Validation;
|
|
|
|
|
private final boolean isIsolateInternalQueries;
|
|
|
|
|
private final AtomicReference<Throwable> lastConnectionFailure;
|
|
|
|
|
private final Executor netTimeoutExecutor;
|
|
|
|
|
|
|
|
|
|
private volatile boolean isValidChecked;
|
|
|
|
|
|
|
|
|
@ -78,7 +82,6 @@ abstract class PoolBase
|
|
|
|
|
this.connectionTimeout = config.getConnectionTimeout();
|
|
|
|
|
this.validationTimeout = config.getValidationTimeout();
|
|
|
|
|
this.lastConnectionFailure = new AtomicReference<>();
|
|
|
|
|
this.netTimeoutExecutor = new SynchronousExecutor();
|
|
|
|
|
|
|
|
|
|
initializeDataSource();
|
|
|
|
|
}
|
|
|
|
@ -199,6 +202,13 @@ abstract class PoolBase
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void shutdownNetworkTimeoutExecutor()
|
|
|
|
|
{
|
|
|
|
|
if (netTimeoutExecutor instanceof ThreadPoolExecutor) {
|
|
|
|
|
((ThreadPoolExecutor) netTimeoutExecutor).shutdownNow();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ***********************************************************************
|
|
|
|
|
// JMX methods
|
|
|
|
|
// ***********************************************************************
|
|
|
|
@ -285,6 +295,7 @@ abstract class PoolBase
|
|
|
|
|
|
|
|
|
|
if (dataSource != null) {
|
|
|
|
|
setLoginTimeout(dataSource, connectionTimeout);
|
|
|
|
|
createNetworkTimeoutExecutor(dataSource, dsClassName, jdbcUrl);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
this.dataSource = dataSource;
|
|
|
|
@ -464,6 +475,24 @@ abstract class PoolBase
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void createNetworkTimeoutExecutor(final DataSource dataSource, final String dsClassName, final String jdbcUrl)
|
|
|
|
|
{
|
|
|
|
|
// Temporary hack for MySQL issue: http://bugs.mysql.com/bug.php?id=75615
|
|
|
|
|
if ((dsClassName != null && dsClassName.contains("Mysql")) ||
|
|
|
|
|
(jdbcUrl != null && jdbcUrl.contains("mysql")) ||
|
|
|
|
|
(dataSource != null && dataSource.getClass().getName().contains("Mysql"))) {
|
|
|
|
|
netTimeoutExecutor = new SynchronousExecutor();
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
ThreadFactory threadFactory = config.getThreadFactory();
|
|
|
|
|
threadFactory = threadFactory != null ? threadFactory : new DefaultThreadFactory("Hikari JDBC-timeout executor", true);
|
|
|
|
|
ThreadPoolExecutor executor = (ThreadPoolExecutor) Executors.newCachedThreadPool(threadFactory);
|
|
|
|
|
executor.allowCoreThreadTimeOut(true);
|
|
|
|
|
executor.setKeepAliveTime(15, TimeUnit.SECONDS);
|
|
|
|
|
netTimeoutExecutor = executor;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static class SynchronousExecutor implements Executor
|
|
|
|
|
{
|
|
|
|
|
/** {@inheritDoc} */
|
|
|
|
|