java - 泄漏的数据库连接

标签 java database jdbc jboss database-connection

找到我的 Java 代码的哪一部分正在打开数据库连接但没有关闭它的最佳方法是什么? 我被困在一个很难调试这个问题的大批量过程中。 我正在使用 JBOSS 应用服务器。

最佳答案

Findbugs有两个规则,这可能会有所帮助。我总觉得这些有用:

ODR: Method may fail to close database resource (ODR_OPEN_DATABASE_RESOURCE)

The method creates a database resource (such as a database connection or row set), does not assign it to any fields, pass it to other methods, or return it, and does not appear to close the object on all paths out of the method. Failure to close database resources on all paths out of a method may result in poor performance, and could cause the application to have problems communicating with the database.

ODR: Method may fail to close database resource on exception (ODR_OPEN_DATABASE_RESOURCE_EXCEPTION_PATH)

The method creates a database resource (such as a database connection or row set), does not assign it to any fields, pass it to other methods, or return it, and does not appear to close the object on all exception paths out of the method. Failure to close database resources on all paths out of a method may result in poor performance, and could cause the application to have problems communicating with the database.

引用:

关于java - 泄漏的数据库连接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9502368/

相关文章:

java - 没有提取任何数据。为什么?

java - 找不到 tools.jar。预计在/usr/lib/jvm/java-7-openjdk-amd64/lib/tools.jar中找到

database - 如何将 Cloudant 数据库备份到 COS?

c++ - 不断重新连接到数据库导致程序变慢

java - 使用 UCanAccess 插入行时更改自动编号值

java - 选择两个值的主键

java - 多用户数据源 - Spring + Hibernate

java - 在不知道类型的情况下在Java中创建集合?

java - 取消套接字和/或线程时遇到问题

php - 在 php for 循环中只显示来自 mysql 数据库的一行?