2013年10月11日星期五

Ask : java.sql.SQLException: closed connection

Heroes : I use hibernate and oracle development based apache james mail system. System is deployed on the server (tomcat) and has been on the run normally. But yesterday suddenly appeared errors, the user can not log into the system . Analysis of a large number of logs found throws java.sql.SQLException: closed connection exceptions.
[2012-08-27 05:40:49] com.csc.mail.jsh.db.hibernate.dao.generic.HibernateDao : [INFO ]  - [findByParameters]excute sql:from com.csc.mail.jsh.db.pojo.TblUser where fullName=? 
[2012-08-27 05:40:49] org.hibernate.util.JDBCExceptionReporter : [WARN ]  - SQL Error: 17008, SQLState: null
[2012-08-27 05:40:49] org.hibernate.util.JDBCExceptionReporter : [ERROR]  - 关闭的连接
[2012-08-27 05:40:49] com.csc.mail.jsh.db.hibernate.dao.generic.HibernateDao : [ERROR]  - [findByParameters] error when excute sql:[from com.csc.mail.jsh.db.pojo.TblUser where fullName=? ],could not execute query,cause:java.sql.SQLException: 关闭的连接
org.hibernate.exception.GenericJDBCException: could not execute query
at org.hibernate.exception.SQLStateConverter.handledNonSpecificException(SQLStateConverter.java:126)
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:114)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:66)
at org.hibernate.loader.Loader.doList(Loader.java:2235)
at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2129)
at org.hibernate.loader.Loader.list(Loader.java:2124)
at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:401)
at org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:363)
at org.hibernate.engine.query.HQLQueryPlan.performList(HQLQueryPlan.java:196)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1149)
at org.hibernate.impl.QueryImpl.list(QueryImpl.java:102)
at com.csc.mail.jsh.db.hibernate.dao.generic.HibernateDao.findByParameters(HibernateDao.java:198)
at com.csc.mail.jsh.business.service.serv.impl.UserServImpl.getUserByName(UserServImpl.java:206)
at com.csc.mail.jsh.action.UserAction.login(UserAction.java:49)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at com.opensymphony.xwork2.DefaultActionInvocation.invokeAction(DefaultActionInvocation.java:441)
at com.opensymphony.xwork2.DefaultActionInvocation.invokeActionOnly(DefaultActionInvocation.java:280)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:243)
at com.opensymphony.xwork2.interceptor.DefaultWorkflowInterceptor.doIntercept

I ask what would be the reason ? I connect to the database hibernate dao, behind every operation has finally, and in finally close the connection inside (closeSession () ;).
my hibernate configuration file does not configure the connection pool .
heroes wing !
------ Solution ---------------------------------------- ----
database, stop the service , and then turn on the line . Likely to visit a few more, the collapse of the bar
------ Solution -------------------------------- ------------
establish a connection pool bar

<property name="minPoolSize" value="1" />
<property name="maxPoolSize" value="300" />
<property name="maxIdleTime" value="60" />
<property name="acquireIncrement" value="5" />
<property name="initialPoolSize" value="1" />


------ Solution ------------------------------------- -------
if you promise to close each operation , and then configure the connection pool bar , is likely to run out of resources
------ Solution ------ --------------------------------------
run a few days , and then suddenly being given , it is some might be a database connection resource has not been closed , reached the maximum number of connections the database , resulting in subsequent requests can not connect to the database , resource depletion , the proposed configuration database connection pool. If the procedure, even when using a connection pool will have a problem.
------ Solution ---------------------------------------- ----


right, or carefully check the program .
------ For reference only -------------------------------------- -

still running the database service . There are three applications under tomcat use the same database . My e-mail system can not log on. Because it is a real production environment , you should allow simultaneous access to hundreds of people is. How to handle large quantities of data access request it ?
------ For reference only -------------------------------------- -
database problems. the service restart the
------ For reference only ------------------------------- --------
this does not know with lazy loading of hibernate there a relationship ? For example, you query an object A, which has a property of the object A object B, then you close the connection after the query and if not dealt with lazy loading this time called A, B attributes of a property will be incorrect report . In add labels lazy = "false" seems to be the landlord online search hibernate lazy loading bar.
at org.hibernate.loader.Loader.doList (Loader.java: 2235) look at the code here , why doList method will be reported can not execute the query ? Debug what
------ For reference only ------------------------------------ ---

only query a user object. In tbl_user table inside, userid, username, passwd , etc. No lazy loading .
------ For reference only -------------------------------------- -

good advice . First with a connection pool , and then follow a few days to see.
------ For reference only -------------------------------------- -
I have encountered this problem, tangled for a few days and eventually get.
------ For reference only -------------------------------------- -
this is sometimes hard to say
------ For reference only ----------------------------- ----------



Hello , I would like to ask , how do you deal with ?
------ For reference only -------------------------------------- -
this seems to be the problem is the greatest number of connections , change the maximum number of connections just fine. oracle11g default maximum number of connections is only 150 .

没有评论:

发表评论