找到我的 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/