所有在池中使用的连接是困&创建新连接 [英] All used connections in pool are sleepy & new connections are created
问题描述
我们正在使用 c3p0
和 Hibernate
。但是hibernate不会重用池中的连接。当我看到 mysql-workbench
的客户端连接,我可以看到他们大部分都在睡眠状态。
We are using c3p0
pooling along with Hibernate
. But hibernate is not re-using the connections in the pool. When I see mysql-workbench
for client connections, I can see most of them are in "Sleep" state. The pool keeps growing over time, by my specified increment, until I eventually run out.
以下是数据配置中的代码片段:
Here's the snippet from the data configuration:
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 - >客户端连接:
MYSQL - Workbench --> Client Connections:
请帮助/建议。
推荐答案
以下解决方案似乎为我工作
Following solution appears to be working for me
连接池Jars已更新。
Connection Pooling Jars has been updated.
- c3p0-0.9.2.1
- hibernate-c3p0-5.1.0.Final
- mchange-commons-java-0.2.3.4
AND
持久性属性已更改如下。
持久性属性
Persistence properties has been changed as below. Persistence Properties
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
FYi ... I am using OS: Ubuntu Java Version: 8 Hibernate Version: 5.1.0
这篇关于所有在池中使用的连接是困&创建新连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!