2014-05-22 151 views
4

爲了解決對DB和空閒連接連接過多的問題,我們做了如下修改配置文件 -休眠 - org.hibernate.exception.GenericJDBCException:無法打開連接

c3p0.min_size=1 
c3p0.max_size=20 
c3p0.timeout=1800 
c3p0.max_statements=50 
connection.release_mode=on_close 

後在嘗試運行應用程序時,我們得到以下異常。請指點爲什麼發生這種情況&這可怎麼修正 -


HTTP Status 500 - org.hibernate.exception.GenericJDBCException: Cannot open connection 

類型異常報告

message org.hibernate.exception.GenericJDBCException: Cannot open connection 

description The server encountered an internal error that prevented it from fulfilling this request. 

exception 

javax.servlet.ServletException: org.hibernate.exception.GenericJDBCException: Cannot open connection 
    org.apache.struts.chain.ComposableRequestProcessor.process(ComposableRequestProcessor.java:286) 
    org.apache.struts.action.ActionServlet.process(ActionServlet.java:1913) 
    org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:462) 
    javax.servlet.http.HttpServlet.service(HttpServlet.java:637) 
    javax.servlet.http.HttpServlet.service(HttpServlet.java:717) 
    com.alci.filters.ParamFilter.doFilter(ParamFilter.java:27) 
root cause 

org.hibernate.exception.GenericJDBCException: Cannot open connection 
    org.hibernate.exception.SQLStateConverter.handledNonSpecificException(SQLStateConverter.java:126) 
    org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:114) 
    org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:66) 
    org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:52) 
    org.hibernate.jdbc.ConnectionManager.openConnection(ConnectionManager.java:449) 
    org.hibernate.jdbc.ConnectionManager.getConnection(ConnectionManager.java:167) 
    org.hibernate.jdbc.AbstractBatcher.prepareQueryStatement(AbstractBatcher.java:161) 
    org.hibernate.loader.Loader.prepareQueryStatement(Loader.java:1577) 
    org.hibernate.loader.Loader.doQuery(Loader.java:696) 
    org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:259) 
    org.hibernate.loader.Loader.doList(Loader.java:2232) 
    org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2129) 
    org.hibernate.loader.Loader.list(Loader.java:2124) 
    org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:401) 
    org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:363) 
    org.hibernate.engine.query.HQLQueryPlan.performList(HQLQueryPlan.java:196) 
    org.hibernate.impl.SessionImpl.list(SessionImpl.java:1149) 
    org.hibernate.impl.QueryImpl.list(QueryImpl.java:102) 
    com.alci.common.LoginAction.login(LoginAction.java:127) 
    sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
    sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) 
    sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) 
    java.lang.reflect.Method.invoke(Method.java:597) 
    org.apache.struts.actions.DispatchAction.dispatchMethod(DispatchAction.java:269) 
    org.apache.struts.actions.DispatchAction.execute(DispatchAction.java:170) 
    org.apache.struts.chain.commands.servlet.ExecuteAction.execute(ExecuteAction.java:58) 
    org.apache.struts.chain.commands.AbstractExecuteAction.execute(AbstractExecuteAction.java:67) 
    org.apache.struts.chain.commands.ActionCommandBase.execute(ActionCommandBase.java:51) 
    org.apache.commons.chain.impl.ChainBase.execute(ChainBase.java:190) 
    org.apache.commons.chain.generic.LookupCommand.execute(LookupCommand.java:304) 
    org.apache.commons.chain.impl.ChainBase.execute(ChainBase.java:190) 
    org.apache.struts.chain.ComposableRequestProcessor.process(ComposableRequestProcessor.java:283) 
    org.apache.struts.action.ActionServlet.process(ActionServlet.java:1913) 
    org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:462) 
    javax.servlet.http.HttpServlet.service(HttpServlet.java:637) 
    javax.servlet.http.HttpServlet.service(HttpServlet.java:717) 
    com.alci.filters.ParamFilter.doFilter(ParamFilter.java:27) 
root cause 

java.sql.SQLException: Connections could not be acquired from the underlying database! 
    com.mchange.v2.sql.SqlUtils.toSQLException(SqlUtils.java:106) 
    com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool.checkoutPooledConnection(C3P0PooledConnectionPool.java:529) 
    com.mchange.v2.c3p0.impl.AbstractPoolBackedDataSource.getConnection(AbstractPoolBackedDataSource.java:128) 
    org.hibernate.connection.C3P0ConnectionProvider.getConnection(C3P0ConnectionProvider.java:78) 
    org.hibernate.jdbc.ConnectionManager.openConnection(ConnectionManager.java:446) 
    org.hibernate.jdbc.ConnectionManager.getConnection(ConnectionManager.java:167) 
    org.hibernate.jdbc.AbstractBatcher.prepareQueryStatement(AbstractBatcher.java:161) 
    org.hibernate.loader.Loader.prepareQueryStatement(Loader.java:1577) 
    org.hibernate.loader.Loader.doQuery(Loader.java:696) 
    org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:259) 
    org.hibernate.loader.Loader.doList(Loader.java:2232) 
    org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2129) 
    org.hibernate.loader.Loader.list(Loader.java:2124) 
    org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:401) 
    org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:363) 
    org.hibernate.engine.query.HQLQueryPlan.performList(HQLQueryPlan.java:196) 
    org.hibernate.impl.SessionImpl.list(SessionImpl.java:1149) 
    org.hibernate.impl.QueryImpl.list(QueryImpl.java:102) 
    com.alci.common.LoginAction.login(LoginAction.java:127) 
    sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
    sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) 
    sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) 
    java.lang.reflect.Method.invoke(Method.java:597) 
    org.apache.struts.actions.DispatchAction.dispatchMethod(DispatchAction.java:269) 
    org.apache.struts.actions.DispatchAction.execute(DispatchAction.java:170) 
    org.apache.struts.chain.commands.servlet.ExecuteAction.execute(ExecuteAction.java:58) 
    org.apache.struts.chain.commands.AbstractExecuteAction.execute(AbstractExecuteAction.java:67) 
    org.apache.struts.chain.commands.ActionCommandBase.execute(ActionCommandBase.java:51) 
    org.apache.commons.chain.impl.ChainBase.execute(ChainBase.java:190) 
    org.apache.commons.chain.generic.LookupCommand.execute(LookupCommand.java:304) 
    org.apache.commons.chain.impl.ChainBase.execute(ChainBase.java:190) 
    org.apache.struts.chain.ComposableRequestProcessor.process(ComposableRequestProcessor.java:283) 
    org.apache.struts.action.ActionServlet.process(ActionServlet.java:1913) 
    org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:462) 
    javax.servlet.http.HttpServlet.service(HttpServlet.java:637) 
    javax.servlet.http.HttpServlet.service(HttpServlet.java:717) 
    com.alci.filters.ParamFilter.doFilter(ParamFilter.java:27) 
root cause 

com.mchange.v2.resourcepool.CannotAcquireResourceException: A ResourcePool could not acquire a resource from its primary factory or source. 
    com.mchange.v2.resourcepool.BasicResourcePool.awaitAvailable(BasicResourcePool.java:1319) 
    com.mchange.v2.resourcepool.BasicResourcePool.prelimCheckoutResource(BasicResourcePool.java:557) 
    com.mchange.v2.resourcepool.BasicResourcePool.checkoutResource(BasicResourcePool.java:477) 
    com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool.checkoutPooledConnection(C3P0PooledConnectionPool.java:525) 
    com.mchange.v2.c3p0.impl.AbstractPoolBackedDataSource.getConnection(AbstractPoolBackedDataSource.java:128) 
    org.hibernate.connection.C3P0ConnectionProvider.getConnection(C3P0ConnectionProvider.java:78) 
    org.hibernate.jdbc.ConnectionManager.openConnection(ConnectionManager.java:446) 
    org.hibernate.jdbc.ConnectionManager.getConnection(ConnectionManager.java:167) 
    org.hibernate.jdbc.AbstractBatcher.prepareQueryStatement(AbstractBatcher.java:161) 
    org.hibernate.loader.Loader.prepareQueryStatement(Loader.java:1577) 
    org.hibernate.loader.Loader.doQuery(Loader.java:696) 
    org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:259) 
    org.hibernate.loader.Loader.doList(Loader.java:2232) 
    org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2129) 
    org.hibernate.loader.Loader.list(Loader.java:2124) 
    org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:401) 
    org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:363) 
    org.hibernate.engine.query.HQLQueryPlan.performList(HQLQueryPlan.java:196) 
    org.hibernate.impl.SessionImpl.list(SessionImpl.java:1149) 
    org.hibernate.impl.QueryImpl.list(QueryImpl.java:102) 
    com.alci.common.LoginAction.login(LoginAction.java:127) 
    sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
    sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) 
    sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) 
    java.lang.reflect.Method.invoke(Method.java:597) 
    org.apache.struts.actions.DispatchAction.dispatchMethod(DispatchAction.java:269) 
    org.apache.struts.actions.DispatchAction.execute(DispatchAction.java:170) 
    org.apache.struts.chain.commands.servlet.ExecuteAction.execute(ExecuteAction.java:58) 
    org.apache.struts.chain.commands.AbstractExecuteAction.execute(AbstractExecuteAction.java:67) 
    org.apache.struts.chain.commands.ActionCommandBase.execute(ActionCommandBase.java:51) 
    org.apache.commons.chain.impl.ChainBase.execute(ChainBase.java:190) 
    org.apache.commons.chain.generic.LookupCommand.execute(LookupCommand.java:304) 
    org.apache.commons.chain.impl.ChainBase.execute(ChainBase.java:190) 
    org.apache.struts.chain.ComposableRequestProcessor.process(ComposableRequestProcessor.java:283) 
    org.apache.struts.action.ActionServlet.process(ActionServlet.java:1913) 
    org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:462) 
    javax.servlet.http.HttpServlet.service(HttpServlet.java:637) 
    javax.servlet.http.HttpServlet.service(HttpServlet.java:717) 
    com.alci.filters.ParamFilter.doFilter(ParamFilter.java:27) 
note The full stack trace of the root cause is available in the Apache Tomcat/6.0.36 logs. 
+0

你能發佈根本原因的完整堆棧跟蹤嗎? –

+0

它是一個共享的tomcat;所以不能立即訪問完整的堆棧跟蹤。 – Suvo

回答

1

你跑出來的數據庫連接。

這意味着兩件事情:

  1. 您的交易需要,因爲查詢速度慢的太多時間,所以連接被關押是爲了太多的時間
  2. 你有非常高的流量需求無法滿足成20個連接池大小。

我建議您閱讀以下read my answer of this SO question

I don't think this settings is recommended

connection.release_mode=on_close 

ON_CLOSE - 基本上是上述的傳統問題。當Hibernate會話首次需要執行某個JDBC訪問並持有該連接時,Hibernate會話將獲得一個連接,直到會話關閉爲 。

on_close - 表示使用ConnectionReleaseMode.ON_CLOSE。此設置爲 左側爲向後兼容,但其使用非常不鼓勵。

嘗試使用「auto」代替。

+0

這是一個測試環境,所以流量很少。另一方面,這種異常出現在登錄,所以在登錄時,緩慢的查詢不是這種情況,我猜 – Suvo

+0

在DEBUG上啓用C3P0日誌,以便您可以實際查看請求連接的數量以及它們釋放的速度。 –

+0

檢查我的更新迴應,我認爲你不應該使用connection.release_mode = on_close選項。 –

相關問題