问题
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 --> Client Connections:
Please help / advice.
回答1:
Following solution appears to be working for me
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 ... I am using OS: Ubuntu Java Version: 8 Hibernate Version: 5.1.0
来源:https://stackoverflow.com/questions/40758569/all-used-connections-in-pool-are-sleepy-new-connections-are-created