• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Knute Snortum
  • Paul Clapham
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Frits Walraven
Bartenders:
  • Ganesh Patekar
  • Tim Holloway
  • salvin francis

org.postgresql.util.PSQLException: This connection has been closed.  RSS feed

 
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am getting the following exceptions while logging in to my application. I have tried to figure it out but its being hard to find a solution. Please suggest a way to resolve.

 
Master Rancher
Posts: 4076
47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

   at com.myapp.utils.DataBaseConnection.getStatement(DataBaseConnection.java:117)
   at com.myapp.utils.DataBaseUtils.execute(DataBaseUtils.java:190)


Can you show us the code around here?
I have a suspicion you are holding onto Connection objects in your utility after they've been closed and are attempting to reuse them.
 
Bartender
Posts: 20736
124
Android Eclipse IDE Java Linux Redhat Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If I read the stack correctly, you're trying to obtain a connection from a Tomcat database connection pool, but the pool connection is closed and therefore useless.

This can happen with a lot of databases where idle connections timeout (and close themselves) if they are not used often enough.

There are options for Tomcat pools that can deal with this, either by "pinging" the connections to keep them alive or by discarding dead ones and creating new replacements. Check the Tomcat docs for details.
 
Dave Tolls
Master Rancher
Posts: 4076
47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The tomcat connection pool handles that by checking whether the connection is alive or not.
At least it has done for a long time now.

As I said, to me that stack trace seems to imply someone holding onto a connection in their utility class, which you should not do.
 
Tim Holloway
Bartender
Posts: 20736
124
Android Eclipse IDE Java Linux Redhat Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Actually, unless default behaviour has changed, the Tomcat connection pool does not do a liveness check by default. Then again, Tomcat 8 switched to a different pool manager, so the documentation should be checked.

I re-read the stack trace and it's possible that a proxied JDBC call is being done rather than a pool fetch. If that's so, my money is on someone having stored a pool Connection object in their session - which, of course, one should never do. Connection is an Interface, and thus not serializable. These days, Tomcat is supposed to reject non-serializable HttpSession objects, but I'm sure there are cases that it doesn't catch.
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!