Tomcat active threads pile up and stalls the server

痞子三分冷 提交于 2019-12-04 10:53:52

Ok, so after analyzing thread dump we realized that somehow many threads were waiting on awaitAvailable() method of c3p0 library which manages DB connections in our application. We found a discussion where somebody suggested to upgrade c3p0 library(from 0.9.1.2 to 0.9.2) because old library had this issue when lot of concurrent connections are checked out of pool, the connection counter value remains bloated after check-ins and hence doesn't allow to check out new connections and results in processes to wait for connections perpetually (we had checkout timeout = 0).

But even after upgrading the library we faced this issue so we used debugUnreturnedConnectionStackTraces property to see what's happening to connections and why are they unavailable. After a day of logs we realized that our code which was leaking DB connections managed by c3p0. There were few flows in our code where we were not calling rollback() specifically in catch block before closing entity Manager in finally block, so in case of exceptions connection was not coming back to pool and if frequency of exception is high(more than size of pool within timeout interval) then all other process threads would pile up to get connection.

Since that code is fixed, we haven't seen any such thread pileup problems.

samlewis

Thread dump analysis is the way forward here. The answers to this question should help you find the root cause: Thread Dump Analysis Tool / Method

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!