Win a copy of TDD for a Shopping Website LiveProject this week in the Testing forum!
  • 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
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

How to know the total connections consumed and the remaining from tomcat JDBC pool ?

 
Ranch Hand
Posts: 558
2
Hibernate Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All,

My question is some what related to my other post, posted in the past. I have following settings in my context.xml



and we are concurrently accessing datasource. I have tried using 10 to 50 concurrent threads on particularly slower queries and connection pooling is working with out any issue for 40 concurrent accesses. However, it is failing quite often for 50 threads, with





I could not understand , why Pool needs to abandon a connection. Is removeAbandoned property is set to true , could that have raised the issue?

Is there any way, I can log the total connections being used out of maximum active connections at any point of time? I looked into JDBC interceptors, but could not find any way to print/log, active connections vs currently being used connections.

Thanks
 
Marshal
Posts: 27211
87
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Kumar Raja wrote:I could not understand , why Pool needs to abandon a connection. Is removeAbandoned property is set to true , could that have raised the issue?



If I'm not mistaken, it isn't the pool which is abandoning a connection. The pool is complaining that some other code has abandoned a connection -- that's quite likely some application code which fails to close a connection after using it, possibly only when an exception is thrown. There's a timeout option in the configuration which tells the pool to remove abandoned connections after 600 of some units, probably seconds.

As for you logging the number of available connections, probably that information isn't accessible to application code. Whether the pool supports something like that, I don't know, but I strongly suggest you review your application code to find out what code is abandoning connections without closing them.
 
Kumar Raja
Ranch Hand
Posts: 558
2
Hibernate Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you Paul. Our code is based on MyBatis framework, where the connection acquiring/closing is all handled by framework. We do little in terms of handling connections directly. However, I will take a look , if anything from code is leading to that problem.

However, I did notice that there was a


I did not bother to mention this problem because, the timing of Out of Memory issue logged is few mins after the first abandoned connection was logged. So, I thought Out of Memory could not have caused the connections being lost. But I think, I might be wron
 
Saloon Keeper
Posts: 25459
180
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
If your code is not properly closing connections (thus returning them to the pool), then the pool will attempt to create a new connection, but the memory resources for the old connection may hang around forever, even after the network link itself has been terminated. That can cause OutOfMemory.

There is a pool option that can cause abandoned connections to be tracked. It's extra overhead that a properly-running production machine wouldn't want, but it can be invaluable for cases like this. What it does is construct an Exception object as part of the process of acquiring the Connection. Later, when the system has determined that the connection has been abandoned, it will throw that cached Exception - which contains a stack trace back to the code that originally acquired the connection.

Knowing where a Connection was obtained is useful because ideally, the connection is used and then returned to the pool as soon as possible. so the connection close() call is often part of the same class that obtained it.
 
Kumar Raja
Ranch Hand
Posts: 558
2
Hibernate Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Tim,

As I mentioned, the whole connection handling is being done by MyBatis and the application code has little handle on the actual connection object. Also I do not see any option that explicitly closes the connection in MyBatis as mentioned in MyBatis.

You mentioned

There is a pool option that can cause abandoned connections to be tracked.

. Is this an option in Tomcat-jdbc pool library ?
 
Tim Holloway
Saloon Keeper
Posts: 25459
180
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


Is this an option in Tomcat-jdbc pool library?



Good question. I hope so, since it's a very useful option. You could always switch to the Apache DBCP for debugging if you need to though.

One thing. Make sure that you have mybatis connections set to "JNDI", not "POOLED". The "POOLED" options construct an in-app connection pool and what we're talking about is an app-external (server-supplied) connection pool. For that you configure the pool as a Tomcat datasource Resource including the assignment of a JNDI pathname. Then set that path in your mybatis configuration. I'm not sure if mybatis wants the full JNDI URL ("java:comp/env/jdbc/mypool") or just the short path that's defined to Tomcat ("jdbc/mypool"), though.
 
Power corrupts. Absolute power xxxxxxxxxxxxxxxx is kinda neat.
Free, earth friendly heat - from the CodeRanch trailboss
https://www.kickstarter.com/projects/paulwheaton/free-heat
reply
    Bookmark Topic Watch Topic
  • New Topic