赞
踩
背景:目前我司使用了阿里的druid来进行连接池管理连接,对接了n种数据库类型,因为创建连接很耗时,所以需要开启保活机制。
项目类型:gradle项目(非spring项目)
dataSource创建方式:DruidDataSourceFactory.createDataSource(),对应源码:
- public static DataSource createDataSource(Properties properties) throws Exception {
- return createDataSource((Map) properties);
- }
-
- public static DataSource createDataSource(Map properties) throws Exception {
- DruidDataSource dataSource = new DruidDataSource();
- config(dataSource, properties);
- return dataSource;
- }
起初对这块不太熟悉,直接在前人的代码上进行了简单修改,发布一段时间后发现并没有生效,后通过查阅资料和翻看源码得知,DruidDataSourceFactory中的config方法并没有keepAlive的参数设置,源码如下:
- public class DruidDataSourceFactory implements ObjectFactory {
-
- private final static Log LOG = LogFactory.getLog(DruidDataSourceFactory.class);
-
- static final int UNKNOWN_TRANSACTIONISOLATION = -1;
-
- public final static String PROP_DEFAULTAUTOCOMMIT = "defaultAutoCommit";
- public final static String PROP_DEFAULTREADONLY = "defaultReadOnly";
- public final static String PROP_DEFAULTTRANSACTIONISOLATION = "defaultTransactionIsolation";
- public final static String PROP_DEFAULTCATALOG = "defaultCatalog";
- public final static String PROP_DRIVERCLASSNAME = "driverClassName";
- public final static String PROP_MAXACTIVE = "maxActive";
- public final static String PROP_MAXIDLE = "maxIdle";
- public final static String PROP_MINIDLE = "minIdle";
- public final static String PROP_INITIALSIZE = "initialSize";
- public final static String PROP_MAXWAIT = "maxWait";
- public final static String PROP_TESTONBORROW = "testOnBorrow";
- public final static String PROP_TESTONRETURN = "testOnReturn";
- public final static String PROP_TIMEBETWEENEVICTIONRUNSMILLIS = "timeBetweenEvictionRunsMillis";
- public final static String PROP_NUMTESTSPEREVICTIONRUN = "numTestsPerEvictionRun";
- public final static String PROP_MINEVICTABLEIDLETIMEMILLIS = "minEvictableIdleTimeMillis";
- public final static String PROP_PHY_TIMEOUT_MILLIS = "phyTimeoutMillis
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。