首页 > 代码库 > Druid “loopWaitCount 0, wait millis 6001” 报错
Druid “loopWaitCount 0, wait millis 6001” 报错
今天总结下自己使用Druid遇到的一个错误“loopWaitCount 0, wait millis 6001”
报错信息:
Caused by: org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection; nested exception is com.alibaba.druid.pool.GetConnectionTimeoutException: loopWaitCount 0, wait millis 6001 at org.springframework.jdbc.datasource.DataSourceUtils.getConnection(DataSourceUtils.java:80) at org.mybatis.spring.transaction.SpringManagedTransaction.openConnection(SpringManagedTransaction.java:80) at org.mybatis.spring.transaction.SpringManagedTransaction.getConnection(SpringManagedTransaction.java:66) at org.apache.ibatis.executor.BaseExecutor.getConnection(BaseExecutor.java:279) at org.apache.ibatis.executor.SimpleExecutor.prepareStatement(SimpleExecutor.java:69) at org.apache.ibatis.executor.SimpleExecutor.doQuery(SimpleExecutor.java:56) at org.apache.ibatis.executor.BaseExecutor.queryFromDatabase(BaseExecutor.java:267) at org.apache.ibatis.executor.BaseExecutor.query(BaseExecutor.java:141) at org.apache.ibatis.executor.BaseExecutor.query(BaseExecutor.java:124) at sun.reflect.GeneratedMethodAccessor33.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at org.apache.ibatis.plugin.Invocation.proceed(Invocation.java:46) at com.tzt.workLog.core.mybatis.plugin.SelectCountSqlInterceptor.intercept(SelectCountSqlInterceptor.java:49) at org.apache.ibatis.plugin.Plugin.invoke(Plugin.java:57) at com.sun.proxy.$Proxy155.query(Unknown Source) at sun.reflect.GeneratedMethodAccessor33.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at org.apache.ibatis.plugin.Invocation.proceed(Invocation.java:46) at com.tzt.workLog.core.mybatis.plugin.OffsetLimitInterceptor.intercept(OffsetLimitInterceptor.java:53) at org.apache.ibatis.plugin.Plugin.invoke(Plugin.java:57) at com.sun.proxy.$Proxy155.query(Unknown Source) at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:101) ... 55 more
系统用的框架是Spring+SpringMVC+Mybatis(SSM),其中把涉及到的两个配置部分列出来:
spring_service.xml <!-- 配置数据库连接 --> <bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource" init-method="init" destroy-method="close"> <!-- 基本属性 url、user、password --> <property name="driverClassName" value="http://www.mamicode.com/${jdbc-0.druid.driver-class}" /> <property name="url" value="http://www.mamicode.com/${jdbc-0.druid.driver-url}" /> <property name="username" value="http://www.mamicode.com/${jdbc-0.user}" /> <property name="password" value="http://www.mamicode.com/${jdbc-0.password}" /> <!-- 配置初始化大小、最小、最大 --> <property name="initialSize" value="http://www.mamicode.com/${jdbc-0.druid.connection-initial-size}" /> <property name="minIdle" value="http://www.mamicode.com/${jdbc-0.druid.connection-minimum-size}" /> <property name="maxActive" value="http://www.mamicode.com/${jdbc-0.druid.connection-maximum-size}" /> <!-- 配置获取连接等待超时的时间 --> <property name="maxWait" value="http://www.mamicode.com/${jdbc-0.druid.connection-maxwait-time}" /> <!-- 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒 --> <property name="timeBetweenEvictionRunsMillis" value="http://www.mamicode.com/${jdbc-0.druid.connection-maxactive-time}" /> <!-- 配置一个连接在池中最小生存的时间,单位是毫秒 --> <property name="minEvictableIdleTimeMillis" value="http://www.mamicode.com/${jdbc-0.druid.connection-minlive-time}" /> <property name="validationQuery" value="http://www.mamicode.com/${jdbc-0.druid.connection-test-sql}" /> <property name="testWhileIdle" value="http://www.mamicode.com/${jdbc-0.druid.test-while-idle}" /> <property name="testOnBorrow" value="http://www.mamicode.com/${jdbc-0.druid.test-on-borrow}" /> <property name="testOnReturn" value="http://www.mamicode.com/${jdbc-0.druid.test-on-return}" /> <!-- 打开PSCache,并且指定每个连接上PSCache的大小 --> <property name="poolPreparedStatements" value="http://www.mamicode.com/${jdbc-0.druid.pool-prepared-statements}" /> <!-- property name="maxPoolPreparedStatementPerConnectionSize" value="http://www.mamicode.com/20" /--> <!-- 数据库密码是否加密 --> <property name="connectionProperties" value="http://www.mamicode.com/config.decrypt=${jdbc-0.druid.config.decrypt}" /> <!-- 配置监控统计拦截的filters --> <property name="filters" value="http://www.mamicode.com/stat,config"/> </bean> db.properties: jdbc-0.druid.alias=productDBPool localhost jdbc-0.druid.driver-class=com.mysql.jdbc.Driver jdbc-0.druid.driver-url=jdbc:mysql://127.0.0.1:3306/zentao?useUnicode=true&characterEncoding=UTF8&zeroDateTimeBehavior=convertToNull jdbc-0.user=root jdbc-0.password=root jdbc-0.druid.connection-initial-size=10 jdbc-0.druid.connection-minimum-size=10 jdbc-0.druid.connection-maximum-size=200 jdbc-0.druid.connection-maxwait-time=6000 jdbc-0.druid.connection-maxactive-time=6000 jdbc-0.druid.connection-minlive-time=300000 jdbc-0.druid.connection-test-sql=select 1 from dual jdbc-0.druid.pool-prepared-statements=false jdbc-0.druid.test-while-idle=true jdbc-0.druid.test-on-borrow=false jdbc-0.druid.test-on-return=false jdbc-0.druid.config.decrypt=false
总结,原因应该是配置中jdbc-0.druid.connection-maximum-size值设置太小,刚开始设置50,后来设置为200
本文出自 “专注于开发技术” 博客,请务必保留此出处http://bingge2015.blog.51cto.com/4332222/1915103
Druid “loopWaitCount 0, wait millis 6001” 报错
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。