池中所有使用过的连接都是困倦的。创建新连接

时间:2016-11-23 07:38:17

标签: java mysql hibernate database-connection c3p0

我们正在使用c3p0汇集Hibernate。但是hibernate并没有重用池中的连接。当我看到mysql-workbench用于客户端连接时,我可以看到大多数都处于“ Sleep ”状态。随着时间的推移,游泳池会按照我指定的增量继续增长,直到我最终用完为止。

以下是数据配置的摘录:

persistenceMap.put(
    "connection.provider_class", "org.hibernate.connection.C3P0ConnectionProvider"
);
persistenceMap.put("hibernate.c3p0.min_size", "1");
persistenceMap.put("hibernate.c3p0.max_size", "5");
persistenceMap.put("hibernate.c3p0.timeout", "5");
persistenceMap.put("hibernate.c3p0.max_statements", "20");
persistenceMap.put("hibernate.c3p0.acquire_increment", "1");
persistenceMap.put("hibernate.c3p0.maxIdleTimeExcessConnections", "3");

MYSQL - Workbench - >客户端连接:

enter image description here

请帮助/建议。

1 个答案:

答案 0 :(得分:0)

以下解决方案似乎对我有用

连接池Jars已更新。

  • c3p0-0.9.2.1
  • hibernate-c3p0-5.1.0.Final
  • mchange-公地java的0.2.3.4

持久性属性已更改如下。 持久性属性

persistenceMap.put("javax.persistence.jdbc.url","jdbc:mysql://localhost:3306/test_db");
persistenceMap.put("javax.persistence.jdbc.user", "root");
persistenceMap.put("javax.persistence.jdbc.password", "root");
persistenceMap.put("javax.persistence.jdbc.driver", "com.mysql.jdbc.Driver");
persistenceMap.put("hibernate.show_sql", "true");
persistenceMap.put("hibernate.format_sql", "true");
persistenceMap.put("hibernate.dialect", "org.hibernate.dialect.MySQLDialect");
persistenceMap.put("hibernate.hbm2ddl.auto", "validate");

persistenceMap.put("hibernate.connection.provider_class", "org.hibernate.connection.C3P0ConnectionProvider");
persistenceMap.put("hibernate.c3p0.min_size", "1");
persistenceMap.put("hibernate.c3p0.max_size", "20");
persistenceMap.put("hibernate.c3p0.timeout", "10");
persistenceMap.put("hibernate.c3p0.max_statements", "50");

FYi ...... 我在用 操作系统:Ubuntu Java版本:8 Hibernate版本:5.1.0

相关问题