All used connections in pool are sleepy & new connections are created

▼魔方 西西 提交于 2019-12-25 08:23:03

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!