当前位置:   article > 正文

非spring项目Druid配置keepAlive参数不生效(附解决方案)_druidkeepalive不生效

druidkeepalive不生效

背景:目前我司使用了阿里的druid来进行连接池管理连接,对接了n种数据库类型,因为创建连接很耗时,所以需要开启保活机制。

项目类型:gradle项目(非spring项目)

dataSource创建方式:DruidDataSourceFactory.createDataSource(),对应源码:

  1. public static DataSource createDataSource(Properties properties) throws Exception {
  2. return createDataSource((Map) properties);
  3. }
  4. public static DataSource createDataSource(Map properties) throws Exception {
  5. DruidDataSource dataSource = new DruidDataSource();
  6. config(dataSource, properties);
  7. return dataSource;
  8. }

起初对这块不太熟悉,直接在前人的代码上进行了简单修改,发布一段时间后发现并没有生效,后通过查阅资料和翻看源码得知,DruidDataSourceFactory中的config方法并没有keepAlive的参数设置,源码如下:

  1. public class DruidDataSourceFactory implements ObjectFactory {
  2. private final static Log LOG = LogFactory.getLog(DruidDataSourceFactory.class);
  3. static final int UNKNOWN_TRANSACTIONISOLATION = -1;
  4. public final static String PROP_DEFAULTAUTOCOMMIT = "defaultAutoCommit";
  5. public final static String PROP_DEFAULTREADONLY = "defaultReadOnly";
  6. public final static String PROP_DEFAULTTRANSACTIONISOLATION = "defaultTransactionIsolation";
  7. public final static String PROP_DEFAULTCATALOG = "defaultCatalog";
  8. public final static String PROP_DRIVERCLASSNAME = "driverClassName";
  9. public final static String PROP_MAXACTIVE = "maxActive";
  10. public final static String PROP_MAXIDLE = "maxIdle";
  11. public final static String PROP_MINIDLE = "minIdle";
  12. public final static String PROP_INITIALSIZE = "initialSize";
  13. public final static String PROP_MAXWAIT = "maxWait";
  14. public final static String PROP_TESTONBORROW = "testOnBorrow";
  15. public final static String PROP_TESTONRETURN = "testOnReturn";
  16. public final static String PROP_TIMEBETWEENEVICTIONRUNSMILLIS = "timeBetweenEvictionRunsMillis";
  17. public final static String PROP_NUMTESTSPEREVICTIONRUN = "numTestsPerEvictionRun";
  18. public final static String PROP_MINEVICTABLEIDLETIMEMILLIS = "minEvictableIdleTimeMillis";
  19. public final static String PROP_PHY_TIMEOUT_MILLIS = "phyTimeoutMillis
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/小蓝xlanll/article/detail/336985
推荐阅读
相关标签
  

闽ICP备14008679号