salilsharma72
asked on
Tomcat and java.sql.SQLException: Connection is closed Exception.
I am using Apache-Tomcat integration using mod_jk2 and using common DBCP for the database connection pool. I am running a java application on the Tomcat server. Apache server just routes request to Tomcat. All application code runs on Tomcat server. It runs fine for couple of day but after that my application stops responding to any requests. This means that when I try to access servlet on my application, it takes forever to process the request which never comes back. I see following errors in my custom logs
ConnectionBean.releaseConn ection Error: java.sql.SQLException: Connection is closed.
My data source properties for commons DB CP are
JdBC Driver Class = oracle.jdbc.driver.OracleD river
Maximum Active Connection = 20
Maximum Idle connection = 10
Max wait for Connection = -1
I have made sure than I am closing a connection after opening it. Could you please advise what could be wrong? Is it a configuration issue or coding issue?
Please help.
ConnectionBean.releaseConn
My data source properties for commons DB CP are
JdBC Driver Class = oracle.jdbc.driver.OracleD
Maximum Active Connection = 20
Maximum Idle connection = 10
Max wait for Connection = -1
I have made sure than I am closing a connection after opening it. Could you please advise what could be wrong? Is it a configuration issue or coding issue?
Please help.
Looks like either a configuration issue in Commons DBCP or a bug in same. Which version of Commons DBCP are you using?
Hi,
Assuming that you have restarted your Tomcat, will this behavior happen instantly or only after several times (days, hours or etc)? If it directly happens, it is probably your connection (configuration). If not, it may be your codes.
Regards
David
Assuming that you have restarted your Tomcat, will this behavior happen instantly or only after several times (days, hours or etc)? If it directly happens, it is probably your connection (configuration). If not, it may be your codes.
Regards
David
ASKER
>>>Which version of Commons DBCP are you using?
I am using Tomcat 5.0 and it is using DBCP which comes with the Tomcat 5.0.
>>> Assuming that you have restarted your Tomcat, will this behavior happen instantly or only after several times (days, hours or etc)?
It does not happen right away, It runs file for couple of days and then stop responding. I think, it was just waiting for DB connection because the max Wait for Connection was set to -1 (means wait for indefinitely)
You can refer to DBCP properties meaning at http://jakarta.apache.org/commons/dbcp/configuration.html
After changing the commons DBCP configuration property Max. Wait for Connection = 90,000 milliseconds (it was -1 originally, means wait indefinitely), I am getting following error. It waits for 90 seconds and then gets another connection after throwing following exception. It looks like connection pool don't have any connection but it gets another connection from somewhere else. Do you guys know why this error is coming?
Thanks for the help.
Error: org.apache.commons.dbcp.SQ LNestedExc eption: Cannot get a connection, pool exhausted
org.apache.commons.dbcp.SQ LNestedExc eption: Cannot get a connection, pool exhausted
at org.apache.commons.dbcp.Po olingDataS ource.getC onnection( PoolingDat aSource.ja va:103)
at org.apache.commons.dbcp.Ba sicDataSou rce.getCon nection(Ba sicDataSou rce.java:5 40)
at com.vision.interfaces.tool s.Connecti onBean.get Connection (Connectio nBean.java :332)
at com.vision.interfaces.tool s.AWSSBean Base.getNe wTransID(A WSSBeanBas e.java:132 )
at com.vision.interfaces.awss sync.rscBe an.makeTra ns(rscBean .java:410)
at com.vision.interfaces.awss sync.rscBe an.process (rscBean.j ava:101)
at com.vision.interfaces.awss sync.syncP rocess.cal lPro(syncP rocess.jav a:112)
at com.vision.interfaces.awss sync.syncP rocess.run (syncProce ss.java:49 )
at com.vision.interfaces.awss sync.SyncR scTask.run (SyncRscTa sk.java:26 )
at SyncReceiveServlet.process File(SyncR eceiveServ let.java:1 53)
at SyncReceiveServlet.process Request(Sy ncReceiveS ervlet.jav a:46)
at SyncReceiveServlet.doGet(S yncReceive Servlet.ja va:55)
at javax.servlet.http.HttpSer vlet.servi ce(HttpSer vlet.java: 689)
at javax.servlet.http.HttpSer vlet.servi ce(HttpSer vlet.java: 802)
at org.apache.catalina.core.A pplication FilterChai n.internal DoFilter(A pplication FilterChai n.java:237 )
at org.apache.catalina.core.A pplication FilterChai n.doFilter (Applicati onFilterCh ain.java:1 57)
at org.apache.catalina.core.S tandardWra pperValve. invoke(Sta ndardWrapp erValve.ja va:214)
at org.apache.catalina.core.S tandardVal veContext. invokeNext (StandardV alveContex t.java:104 )
at org.apache.catalina.core.S tandardPip eline.invo ke(Standar dPipeline. java:520)
at org.apache.catalina.core.S tandardCon textValve. invokeInte rnal(Stand ardContext Valve.java :198)
at org.apache.catalina.core.S tandardCon textValve. invoke(Sta ndardConte xtValve.ja va:152)
at org.apache.catalina.core.S tandardVal veContext. invokeNext (StandardV alveContex t.java:104 )
at org.apache.catalina.core.S tandardPip eline.invo ke(Standar dPipeline. java:520)
at org.apache.catalina.core.S tandardHos tValve.inv oke(Standa rdHostValv e.java:137 )
at org.apache.catalina.core.S tandardVal veContext. invokeNext (StandardV alveContex t.java:104 )
at org.apache.catalina.valves .ErrorRepo rtValve.in voke(Error ReportValv e.java:118 )
at org.apache.catalina.core.S tandardVal veContext. invokeNext (StandardV alveContex t.java:102 )
at org.apache.catalina.core.S tandardPip eline.invo ke(Standar dPipeline. java:520)
at org.apache.catalina.core.S tandardEng ineValve.i nvoke(Stan dardEngine Valve.java :109)
at org.apache.catalina.core.S tandardVal veContext. invokeNext (StandardV alveContex t.java:104 )
at org.apache.catalina.core.S tandardPip eline.invo ke(Standar dPipeline. java:520)
at org.apache.catalina.core.C ontainerBa se.invoke( ContainerB ase.java:9 29)
at org.apache.coyote.tomcat5. CoyoteAdap ter.servic e(CoyoteAd apter.java :160)
at org.apache.jk.server.JkCoy oteHandler .invoke(Jk CoyoteHand ler.java:3 00)
at org.apache.jk.common.Handl erRequest. invoke(Han dlerReques t.java:374 )
at org.apache.jk.common.Chann elSocket.i nvoke(Chan nelSocket. java:743)
at org.apache.jk.common.Chann elSocket.p rocessConn ection(Cha nnelSocket .java:675)
at org.apache.jk.common.Socke tConnectio n.runIt(Ch annelSocke t.java:866 )
at org.apache.tomcat.util.thr eads.Threa dPool$Cont rolRunnabl e.run(Thre adPool.jav a:683)
at java.lang.Thread.run(Unkno wn Source)
Caused by: java.util.NoSuchElementExc eption: Timeout waiting for idle object
at org.apache.commons.pool.im pl.Generic ObjectPool .borrowObj ect(Generi cObjectPoo l.java:756 )
at org.apache.commons.dbcp.Po olingDataS ource.getC onnection( PoolingDat aSource.ja va:95)
... 39 more
I am using Tomcat 5.0 and it is using DBCP which comes with the Tomcat 5.0.
>>> Assuming that you have restarted your Tomcat, will this behavior happen instantly or only after several times (days, hours or etc)?
It does not happen right away, It runs file for couple of days and then stop responding. I think, it was just waiting for DB connection because the max Wait for Connection was set to -1 (means wait for indefinitely)
You can refer to DBCP properties meaning at http://jakarta.apache.org/commons/dbcp/configuration.html
After changing the commons DBCP configuration property Max. Wait for Connection = 90,000 milliseconds (it was -1 originally, means wait indefinitely), I am getting following error. It waits for 90 seconds and then gets another connection after throwing following exception. It looks like connection pool don't have any connection but it gets another connection from somewhere else. Do you guys know why this error is coming?
Thanks for the help.
Error: org.apache.commons.dbcp.SQ
org.apache.commons.dbcp.SQ
at org.apache.commons.dbcp.Po
at org.apache.commons.dbcp.Ba
at com.vision.interfaces.tool
at com.vision.interfaces.tool
at com.vision.interfaces.awss
at com.vision.interfaces.awss
at com.vision.interfaces.awss
at com.vision.interfaces.awss
at com.vision.interfaces.awss
at SyncReceiveServlet.process
at SyncReceiveServlet.process
at SyncReceiveServlet.doGet(S
at javax.servlet.http.HttpSer
at javax.servlet.http.HttpSer
at org.apache.catalina.core.A
at org.apache.catalina.core.A
at org.apache.catalina.core.S
at org.apache.catalina.core.S
at org.apache.catalina.core.S
at org.apache.catalina.core.S
at org.apache.catalina.core.S
at org.apache.catalina.core.S
at org.apache.catalina.core.S
at org.apache.catalina.core.S
at org.apache.catalina.core.S
at org.apache.catalina.valves
at org.apache.catalina.core.S
at org.apache.catalina.core.S
at org.apache.catalina.core.S
at org.apache.catalina.core.S
at org.apache.catalina.core.S
at org.apache.catalina.core.C
at org.apache.coyote.tomcat5.
at org.apache.jk.server.JkCoy
at org.apache.jk.common.Handl
at org.apache.jk.common.Chann
at org.apache.jk.common.Chann
at org.apache.jk.common.Socke
at org.apache.tomcat.util.thr
at java.lang.Thread.run(Unkno
Caused by: java.util.NoSuchElementExc
at org.apache.commons.pool.im
at org.apache.commons.dbcp.Po
... 39 more
Hi,
I am not pretty sure but do you have any codes that do not close the connection? Can you post your codes on how do you initialize and finalize the connection from DB?
Additionally, please have a look at the Preventing DB Connection Pools Leak part in
http://jakarta.apache.org/tomcat/tomcat-5.5-doc/jndi-datasource-examples-howto.html
I hope it worked.
David
I am not pretty sure but do you have any codes that do not close the connection? Can you post your codes on how do you initialize and finalize the connection from DB?
Additionally, please have a look at the Preventing DB Connection Pools Leak part in
http://jakarta.apache.org/tomcat/tomcat-5.5-doc/jndi-datasource-examples-howto.html
I hope it worked.
David
ASKER
I found the solution; my code was not closing a connection at one point. Setting logAbandoned="true" in DBCP properties is really helpful as it will tell you the exact line of code where connection was opened but never closed. This kind of feature is not available in many application servers but it is available in Tomcat. I was pleasantly surprised.
Thanks everyone for the help
Thanks everyone for the help
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.