• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Ben Shoots
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • 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
 
Tim Holloway
Saloon Keeper
Pie
Posts: 17989
47
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • 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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic