当前位置:   article > 正文

c3p0异常_attempted to use pool

attempted to use pool
  1. Caused by: com.mchange.v2.resourcepool.ResourcePoolException: Attempted to use a closed or broken resource pool
  2. at com.mchange.v2.resourcepool.BasicResourcePool.ensureNotBroken(BasicResourcePool.java:1735)
  3. at com.mchange.v2.resourcepool.BasicResourcePool.prelimCheckoutResource(BasicResourcePool.java:573)
  4. at com.mchange.v2.resourcepool.BasicResourcePool.checkoutResource(BasicResourcePool.java:526)
  5. at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool.checkoutAndMarkConnectionInUse(C3P0PooledConnectionPool.java:755)
  6. at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool.checkoutPooledConnection(C3P0PooledConnectionPool.java:682)
  7. ... 88 more
  8. 四月 20, 2015 3:17:58 下午 org.apache.catalina.core.ApplicationContext log
  9. 信息: Initializing Spring FrameworkServlet 'springServlet'
  10. 四月 20, 2015 3:18:38 下午 org.apache.catalina.startup.HostConfig deployDirectory
  11. 信息: Deploying web application directory ROOT
  12. 四月 20, 2015 3:18:39 下午 org.apache.coyote.http11.Http11Protocol start
  13. 信息: Starting Coyote HTTP/1.1 on http-8888
  14. 四月 20, 2015 3:18:42 下午 org.apache.jk.common.ChannelSocket init
  15. 信息: JK: ajp13 listening on /0.0.0.0:8009
  16. 四月 20, 2015 3:18:42 下午 org.apache.jk.server.JkMain start
  17. 信息: Jk running ID=0 time=0/481 config=null
  18. 四月 20, 2015 3:18:42 下午 org.apache.catalina.startup.Catalina start
  19. 信息: Server startup in 142564 ms


spring配置

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <beans xmlns="http://www.springframework.org/schema/beans"
  3. xmlns:security="http://www.springframework.org/schema/security"
  4. xmlns:context="http://www.springframework.org/schema/context"
  5. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop"
  6. xmlns:tx="http://www.springframework.org/schema/tx"
  7. xsi:schemaLocation="http://www.springframework.org/schema/beans
  8. http://www.springframework.org/schema/beans/spring-beans.xsd
  9. http://www.springframework.org/schema/context
  10. http://www.springframework.org/schema/context/spring-context.xsd
  11. http://www.springframework.org/schema/tx
  12. http://www.springframework.org/schema/tx/spring-tx.xsd
  13. http://www.springframework.org/schema/aop
  14. http://www.springframework.org/schema/aop/spring-aop-2.0.xsd">
  15. <!-- bean的生命周期回调函数 <bean class="com.test.control.MyBeanPostProcessor"/> -->
  16. <import resource="/beans.xml" />
  17. <context:component-scan base-package="com.h3c.itac" />
  18. <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"
  19. destroy-method="close">
  20. <property name="driverClass">
  21. <value>com.mysql.jdbc.Driver</value>
  22. </property>
  23. <property name="jdbcUrl">
  24. <value>jdbc:mysql://localhost:3306/itac</value>
  25. </property>
  26. <property name="user">
  27. <value>root</value>
  28. </property>
  29. <property name="password">
  30. <value>root</value>
  31. </property>
  32. <!--连接池中保留的最小连接数。 -->
  33. <property name="minPoolSize" value="10" />
  34. <!--连接池中保留的最大连接数。Default: 15 -->
  35. <property name="maxPoolSize" value="100" />
  36. <!--最大空闲时间,1800秒内未使用则连接被丢弃。若为0则永不丢弃。Default: 0 -->
  37. <property name="maxIdleTime" value="1800" />
  38. <!--当连接池中的连接耗尽的时候c3p0一次同时获取的连接数。Default: 3 -->
  39. <property name="acquireIncrement" value="5" />
  40. <property name="maxStatements" value="1000" />
  41. <property name="initialPoolSize" value="10" />
  42. <!--每60秒检查所有连接池中的空闲连接。Default: 0 -->
  43. <property name="idleConnectionTestPeriod" value="60" />
  44. <!--定义在从数据库获取新连接失败后重复尝试的次数。Default: 30 -->
  45. <property name="acquireRetryAttempts" value="30" />
  46. <property name="breakAfterAcquireFailure" value="true" />
  47. <property name="testConnectionOnCheckout" value="false" />
  48. </bean>
  49. <bean id="sessionFactory"
  50. class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
  51. <property name="dataSource" ref="dataSource" />
  52. <property name="packagesToScan" value="com.h3c.itac" />
  53. <property name="hibernateProperties">
  54. <value>
  55. hibernate.dialect=org.hibernate.dialect.MySQL5Dialect
  56. hibernate.hbm2ddl.auto=update
  57. hibernate.connection.autocommit=true
  58. hibernate.show_sql=false
  59. hibernate.format_sql=false
  60. hibernate.cache.use_second_level_cache=true
  61. hibernate.cache.use_query_cache=false
  62. hibernate.current_session_context_class=org.springframework.orm.hibernate4.SpringSessionContext
  63. </value>
  64. </property>
  65. </bean>
  66. <bean id="txManager"
  67. class="org.springframework.orm.hibernate4.HibernateTransactionManager">
  68. <property name="sessionFactory" ref="sessionFactory"></property>
  69. <property name="nestedTransactionAllowed" value="true" />
  70. </bean>
  71. <bean class="com.h3c.itac.HibernateBaseDao">
  72. </bean>
  73. <tx:annotation-driven transaction-manager="txManager" proxy-target-class="true"
  74. mode="proxy" />
  75. </beans>

使用的jar

  1. antlr-2.7.7.jar
  2. aopalliance.jar
  3. aspectj-1.8.3.jar
  4. aspectjweaver-1.6.9.jar
  5. c3p0-0.9.2.1.jar
  6. commons-logging-1.0.4.jar
  7. dom4j-1.6.1.jar
  8. gson-2.2.4.jar
  9. hibernate-c3p0-4.3.7.Final.jar
  10. hibernate-commons-annotations-4.0.5.Final.jar
  11. hibernate-core-4.3.7.Final.jar
  12. hibernate-jpa-2.1-api-1.0.0.Final.jar
  13. javassist-3.18.1-GA.jar
  14. jboss-logging-3.1.3.GA.jar
  15. jboss-logging-annotations-1.2.0.Beta1.jar
  16. jboss-transaction-api_1.2_spec-1.0.0.Final.jar
  17. log4j-1.2.17.jar
  18. mchange-commons-java-0.2.3.4.jar
  19. mysql-connector-java-5.1.18-bin.jar
  20. slf4j-api-1.6.1.jar
  21. spring-aop-4.1.2.RELEASE.jar
  22. spring-aspects-4.1.2.RELEASE.jar
  23. spring-beans-4.1.2.RELEASE.jar
  24. spring-context-4.1.2.RELEASE.jar
  25. spring-context-support-4.1.2.RELEASE.jar
  26. spring-core-4.1.2.RELEASE.jar
  27. spring-expression-4.1.2.RELEASE.jar
  28. spring-jdbc-4.1.2.RELEASE.jar
  29. spring-orm-4.1.2.RELEASE.jar
  30. spring-security-config-3.2.5.RELEASE.jar
  31. spring-security-core-3.2.5.RELEASE-javadoc.jar
  32. spring-security-core-3.2.5.RELEASE.jar
  33. spring-security-web-3.2.5.RELEASE.jar
  34. spring-tx-4.1.2.RELEASE.jar
  35. spring-web-4.1.2.RELEASE.jar
  36. spring-webmvc-4.1.2.RELEASE.jar
  37. sqlite-jdbc-3.8.6.jar
  38. standard.jar


其实问题很清楚了, Attempted to use a closed or broken resource pool,刚开始看到这句话感觉是数据源问题,然后去检查数据源的相关c3p0的相关jar和配置,网上有种说法是缺少配置:

  1. <property name="acquireRetryAttempts" value="30" />
  2. <property name="breakAfterAcquireFailure" value="true" />
  3. <property name="testConnectionOnCheckout" value="false" />
但是本xml中已经进行了这个配置,所以问题不是在这里,但是比较奇怪的是:cmd命令行可以顺利的连接上mysql

当时还不是特别确定是不是c3p0的问题,所以,就想到用普通的jdbc程序连接一下数据库试试。


首先可以确定的是,我用root用户名和root密码在cmd中是可以连接上mysql的,所以就比较奇怪了,为什么cmd可以,编程却不可以

,最终原因是本地mysql的问题,更换了sqlite数据库,则可以正常运行




声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/不正经/article/detail/627431
推荐阅读
  

闽ICP备14008679号