* jdbc pool : lhttp://tomcat.apache.org/tomcat-7.0-doc/jdbc-pool.html (TheJDBC Connection Poolorg.apache.tomcat.jdbc.pool is a replacement or an alternative to theApache Commons DBCP connection pool. )
* druid的中文配置说明 (配置项和dbcp是一致的),不如英文来的明了。” https://github.com/alibaba/druid/wiki/DruidDataSource配置属性列表 “
jdbc连接池连接过多且又空闲不使用就需要进行回收。这个不管是数据库连接池还是java线程池都有一样的诉求。
jdbc连接池不同于线程池的是,连接有可能提前被数据库关闭掉。这个将导致后续的请求使用该连接的时候抛错或者 通过重连导致超时。
故为解决该问题需要配置配置。
<!-- 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒 --> <property name="timeBetweenEvictionRunsMillis" value="${jdbc.idleConnectionTestPeriod}" /> <!-- 配置一个连接在池中最小生存的时间,单位是毫秒 --> <property name="minEvictableIdleTimeMillis" value="${jdbc.maxIdleTime}" />
我们系统中目前设置的是jdbc.maxIdleTime=14400000 ,minIdle=2014400000/3600/1000 = 4小时我们的数据库目前设置为15分钟即断开。故客户端连接池设置时间短一点:10分钟,会回收连接直到20.剩下的20个连接即使一直空闲也不回收,符合连接池的意义。但是数据库会把这20个连接关闭。故依旧无法解决 抛错或者超时的问题。只能查看druid的监控,查看峰值活跃数。不停调整值{ "url": "jdbc:mysql://xxxx?characterEncoding=UTF-8", "dbType": "mysql", "name": "DataSource-4129454", "activeCount": 0, "activePeak": 4, "activePeakTime": "2016-02-16 00:00:03", "poolingCount": 5, "poolingPeak": 6, "poolingPeakTime": "2016-02-15 23:59:25", "connectCount": 8788, "closeCount": 8787, "executeCount": 9757, "commitCount": 485, "pstmtCacheHitCount": 9753, "pstmtCacheMissCount": 4, "startTransactionCount": 485, "transactionHistogram": [ 0, 485 ], "connectionHoldTimeHistogram": [ 8274, 513 ], ] }{ "url": "jdbc:mysql://xxx?characterEncoding=UTF-8", "dbType": "mysql", "name": "DataSource-4129454", "activeCount": 0, "activePeak": 4, "activePeakTime": "2016-02-15 22:00:10", "poolingCount": 4, "poolingPeak": 4, "poolingPeakTime": "2016-02-15 21:59:13", "connectCount": 9354, "closeCount": 9354, "executeCount": 9962, "errorCount": 1, "commitCount": 305, "pstmtCacheHitCount": 9956, "pstmtCacheMissCount": 6, "startTransactionCount": 305, "transactionHistogram": [ 0, 305 ], "connectionHoldTimeHistogram": [ 8999, 353, 2 ] }