paip.提高穩定性---自動檢測sleep mysql資料庫死串連以及kill

來源:互聯網
上載者:User

paip.提高穩定性---自動檢測sleep mysql資料庫死串連以及kill

作者Attilax  艾龍,  EMAIL:1466519819@qq.com
來源:attilax的專欄
地址:http://blog.csdn.net/attilax

//////檢測本應用的泄漏資料庫過濾
主要原理是:
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());

    


相關文章

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.