gpt4 book ai didi

java - 池中所有已使用的连接都处于 hibernate 状态并创建新连接

转载 作者:行者123 更新时间:2023-11-29 19:53:23 25 4
gpt4 key购买 nike

我们将 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 - 工作台 --> 客户端连接:

enter image description here

请提供帮助/建议。

最佳答案

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

连接池 Jars 已更新。

  • c3p0-0.9.2.1
  • hibernate-c3p0-5.1.0.Final
  • mchange-commons-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");

仅供引用...我在用操作系统:UbuntuJava版本:8 hibernate 版本:5.1.0

关于java - 池中所有已使用的连接都处于 hibernate 状态并创建新连接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40758569/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com