• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

Tomcat Connection pool creating too many connections, stuck in sleep mode

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm using Tomcat 7's connection pool with MySQL. Testing my application, it doesn't reuse anything from the pool, but ends up creating a new pool, to eventually where I cannot use the database because there are hundreds of sleeping connections in the pool when the max active size for the pool is set to 20.

See here for reference:

It creates exactly 10 for each request, which is the minIdle attribute as seen below.

Here is the sample test code embedded into a jsp page. The code is not the code in my application and just used to see if the issue was with my code, but the problem still persisted.



Here is my context.xml file:



I'm sure I can use removeAbandonedTimeout to a low number and it would purge all these sleeping connections, but that wouldn't fix the real problem would it? Does anyone know what I'm doing wrong?

Thank you very much,
Ben
 
Saloon Keeper
Posts: 28319
210
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I heartily recommend NEVER ignoring exceptions. Dump the stacktrace to the log, but don't just drop them. Otherwise when things go mysteriously wrong, you won't have a clue.

There is a DBCP option that allows tracking connections. What it does is generate an Exception (with associated stacktrace) when you request a connection from the pool. This Exception is then attached to the Connection instead of being thrown. If the orphan connection cleanup service picks up an abandoned connection of this type, it prints the stacktrace, which tells you what part of the app is creating improperly-released connections.

The orphan connection problem is one reason I like the Spring Framework. It manages the grunt work, including ensuring that connections get returned to the pool.
 
Listen. That's my theme music. That's how I know I'm a super hero. That, and this tiny ad told me:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic