//////检测本应用的泄漏数据库过滤 主要原理是: a.在调用conn时,得到conn的localport,存储为一个list b.从mysql查询本机器所有的连接 检测本机的泄漏数据库连接(大概) select * from information_schema.processlist where user=root and host like 192.168.1
//////检测本应用的泄漏数据库过滤
主要原理是:
a.在调用conn时,得到conn的localport,存储为一个list
b.从mysql查询本机器所有的连接
检测本机的泄漏数据库连接(大概)
select * from information_schema.processlist where user='root' and host like '192.168.1.1:%' and db='dbname' command='sleep' and time>60 and state='' and info is NULL
529 root atipc:8213 test Sleep 9932
c.判断localport,取得交集..就是本应用发出的conn...
d.循环调用使用kill id ,释放连接..
最难点的部分在于得到发出的连接对应的localport...
解开mysql jdbc5.1.7 驱动源码..把MysqlIO.java以及JDBC4Connection.java加入源码包..这样生成的class会先加载
修改/src/com/mysql/jdbc/MysqlIO.java,不个默认private的Socket改成public的..
/**attilax o13,change protect to public The connection to the server */
public Socket mysqlConnection = null;
修改JDBC4Connection.java, 不个默认protect的getIO()改成public的..
/**
* attilax o13
*/
public MysqlIO getIO() throws SQLException {
return super.getIO();
}
这样走ok兰..代码中调用...
JDBC4Connection conx=(JDBC4Connection) con;
MysqlIO mio=conx.getIO();
System.out.println(mio.mysqlConnection.getLocalPort());
Statement:The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn