[英]How to check connection leak using regular expression?
我必須檢查應用程序中的連接泄漏,即未關閉的打開的連接。
搜索之后,我發現已經打開了數千次連接,但是無法手動訪問每個代碼片段並檢查連接是否關閉。
我認為,使用正則表達式是可能的,但事實是,我對regex並不了解,因此我可以編寫一個正則表達式。
請提出一個正則表達式,以檢查是否有打開的連接是否已關閉的Java文件。
我的代碼模式是這樣的。
try {
/*
Some code goes here
*/
con = EJBUtil.getConnection(JNDI_NAME);
/*
Some code goes here
*/
}
finally
{
/*
Some code goes here
*/
DBUtil.close(con);
or
closeConnection.close(con);
/*
Some code goes here
*/
}
正則表達式不是這里的好工具。 只需在文件中搜索getConnection
然后在close
搜索相應的變量即可。
您可以編寫腳本來計算打開和關閉子句
例如,這個(perl腳本)輸出的文件中沒有打開方括號的行:
#!/usr/bin/perl -w # brackets.pl: output filenames with unmatched brackets (with hint to linenumber) # example: ./brackets *.c while(<>) { if(!defined($f) or $f ne $ARGV){$f=$ARGV;$l=0} $l++; push @ar,"$f: $l" if(/{/); pop @ar if(/}/) } print"$_\n" for(@ar);
您可以用正則表達式替換括號
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.