Statement leak detection and reclaim
By shalini_m on Feb 28, 2011
Statement leak detection is a new feature to detect any statements that have not been closed by the applications for a specified time period.
Why is this important?
Applications might run out of cursors if the statement objects are not
closed and hence detecting them as leaks can help developers and
administrators to make sure that the statement objects are indeed closed after use.
How to know if there is a statement leak?
The stack trace of the caller that creates the statement is logged in the server.log when a statement leak is detected.
Enabling Statement leak detection
Statement leak timeout can be enabled by setting a connection pool configuration attribute statement-leak-timeout-in-seconds. Default value of this attribute is zero, indicating that the statement leak detection is turned off. Leak detection is enabled when set to a positive non-zero value. After this timeout, the statement object is considered to be leaked.
Enabling Statement leak reclaim
Statement leak reclaim can be enabled by setting a connection pool configuration attribute statement-leak-reclaim. By default, this attribute is set to false and the statement leak
reclaim is disabled. For statement reclaim to work, statement leak
timeout need to be enabled. Once a statement leak is detected, leaked
statement is reclaimed. During a statement reclaim, the leaked
statement(s) is closed.
Points to note
- Connection leak timeout should be greater than the Statement leak
- Statement Timeout should be lesser than the Statement leak
The total number of statement leaks for the jdbc connection pool at the sample time can be got using the command line interface. When monitoring is set to HIGH, this monitoring statistic is of the form
server.resources.testPool.numpotentialstatementleak-count = 6
The corresponding amx objectName for collecting this monitoring statistic programmatically is
Statement leak detection is done for all new connections got in an
application for an active pool. Similarly, the monitoring statistics are collected for these new connections from which statements are created.