2016-11-23 14 views
0

我們使用c3p0Hibernate一起使用。但是hibernate並沒有重用池中的連接。當我看到mysql-workbench用於客戶端連接時,我可以看到其中大部分都處於「睡眠」狀態。隨着時間的推移,游泳池按照我指定的增量持續增長,直到我最終耗盡。游泳池中使用的所有連接都很困難,並建立了新連接

下面是從數據配置片斷:

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

請幫助/諮詢。

回答

0

以下解決方案似乎是爲我工作

連接池罐已被更新。

  • 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"); 

僅供參考... 我使用 操作系統:Ubuntu的 Java版本:8 Hibernate的版本:5.1.0