是否有任何工具或技术可以识别打开的ResultSet [英] Is there any tool or technique to identify opened ResultSet

查看:107
本文介绍了是否有任何工具或技术可以识别打开的ResultSet的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在使用 SQLIte 来持久化数据的Java应用程序中,我正在使用 java.sql 打包访问我的数据库.

In the context of a java application using SQLIte to persist data I am using the Zentus JDBC driver. Thus I am using the java.sql package to acces my database.

我遇到了一些奇怪的问题(在同一个数据库中有多个Connection对象的环境中),我可以肯定我的问题来自未关闭的ResultSet.

I am facing some strange (in a an environment with several Connection objects on the same database) issues and I am pretty sure my problems come from non closed ResultSet.

是否有任何工具或技术可以让我发现在源代码中查找这些非封闭对象的位置?

Is there any tool or technique allowing me to spot where to look in my source code to find these non closed objects ?

编辑可能正在使用 AspectJ ??

Edit May be using AspectJ ??

推荐答案

似乎一个方面可能会有所帮助.

It seems like an aspect may be helpful.

如何包装在方面中返回结果集的方法.像这样:

How about wrapping the methods which return a result set in an aspect. Something like:

execution(public java.sql.ResultSet+ java.sql.Statement+.*(..))

另一方面可以监视ResultSets上的close方法.也许:

Another aspect can monitor the close method on ResultSets. Perhaps:

execution(public * java.sql.ResultSet.close())

第一个方面是,在返回每个ResultSet时,将创建一个新的Exception对象,并将其存储在使用ResultSet的哈希值作为键的静态Map中.第二个方面,在结果集关闭时,将使用相同的哈希码作为键从Map中删除Exception.映射在任何时候都应为每个打开的ResultSet都具有一个异常实例.从异常中,您可以获得堆栈跟踪,以查看ResultSet的打开位置.

The first aspect would, on the return of every ResultSet, create a new Exception object and store it in a static Map somewhere using the hash of the ResultSet as the key. The second aspect, on the closing of the result set, would remove the Exception from the Map using the same hashcode as a key. At any time, the map should have one exception instance for every open ResultSet. From the exception you can obtain a stack trace to see where the ResultSet was opened.

您也许可以存储一个更大的对象,其中包括一个异常和一些其他上下文信息.创建ResultSet的时间等.

You could perhaps store a larger object which includes an exception and some other contextual information; time that the ResultSet was created, etc.

这篇关于是否有任何工具或技术可以识别打开的ResultSet的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆