mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
添加usePingMethod配置
This commit is contained in:
@@ -170,6 +170,8 @@ public abstract class DruidAbstractDataSource extends WrapperAdapter implements
|
||||
protected volatile long timeBetweenConnectErrorMillis = DEFAULT_TIME_BETWEEN_CONNECT_ERROR_MILLIS;
|
||||
|
||||
protected volatile ValidConnectionChecker validConnectionChecker = null;
|
||||
|
||||
protected volatile boolean usePingMethod = false;
|
||||
|
||||
protected final Map<DruidPooledConnection, Object> activeConnections = new IdentityHashMap<DruidPooledConnection, Object>();
|
||||
protected final static Object PRESENT = new Object();
|
||||
@@ -641,6 +643,14 @@ public abstract class DruidAbstractDataSource extends WrapperAdapter implements
|
||||
this.validConnectionChecker = validConnectionChecker;
|
||||
}
|
||||
|
||||
public boolean isUsePingMethod() {
|
||||
return usePingMethod;
|
||||
}
|
||||
|
||||
public void setUsePingMethod(boolean usePingMethod) {
|
||||
this.usePingMethod = usePingMethod;
|
||||
}
|
||||
|
||||
public String getValidConnectionCheckerClassName() {
|
||||
if (validConnectionChecker == null) {
|
||||
return null;
|
||||
|
||||
@@ -1318,7 +1318,7 @@ public class DruidDataSource extends DruidAbstractDataSource implements DruidDat
|
||||
|
||||
String realDriverClassName = driver.getClass().getName();
|
||||
if (JdbcUtils.isMySqlDriver(realDriverClassName)) {
|
||||
this.validConnectionChecker = new MySqlValidConnectionChecker();
|
||||
this.validConnectionChecker = new MySqlValidConnectionChecker(usePingMethod);
|
||||
|
||||
} else if (realDriverClassName.equals(JdbcConstants.ORACLE_DRIVER)
|
||||
|| realDriverClassName.equals(JdbcConstants.ORACLE_DRIVER2)) {
|
||||
|
||||
+3
-3
@@ -45,7 +45,7 @@ public class MySqlValidConnectionChecker extends ValidConnectionCheckerAdapter i
|
||||
private Method ping;
|
||||
private boolean usePingMethod = false;
|
||||
|
||||
public MySqlValidConnectionChecker(){
|
||||
public MySqlValidConnectionChecker(boolean usePingMethod){
|
||||
try {
|
||||
clazz = Utils.loadClass("com.mysql.jdbc.MySQLConnection");
|
||||
if (clazz == null) {
|
||||
@@ -56,8 +56,8 @@ public class MySqlValidConnectionChecker extends ValidConnectionCheckerAdapter i
|
||||
ping = clazz.getMethod("pingInternal", boolean.class, int.class);
|
||||
}
|
||||
|
||||
if (ping != null) {
|
||||
usePingMethod = true;
|
||||
if (ping != null && usePingMethod == true) {
|
||||
this.usePingMethod = true;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
LOG.warn("Cannot resolve com.mysql.jdbc.Connection.ping method. Will use 'SELECT 1' instead.", e);
|
||||
|
||||
Reference in New Issue
Block a user