我很新使用jtds連接驅動程序。我已經編寫了一個應用程序,它可以讀取大約2500個大型xml文件,並對SQL服務器進行SQL查詢和運行。我看到,當我達到一定數量的XML時,我的程序運行時內存不足。我使用內存分析器在eclipse中檢查了我的phd dump文件,發現net.sourceforge.jtds.jdbc.cache.SimpleLRUCache持有大量內存。我連接到SQL服務器一次,並保持連接活着,直到我衝我所有的查詢。以下是我對服務器運行查詢的代碼。我不知道如何獲得net.sourceforge.jtds.jdbc.cache.SimpleLRUCache類的句柄,因爲它有一個明確的方法,我認爲可以清除緩存。我再次對jtds的驅動程序不太瞭解。任何人都可以幫我解決這個問題嗎?net.sourceforge.jtds.jdbc.cache.SimpleLRUCache導致內存泄漏
public boolean runQueries(String query){
if (getConn() != null && query != null) {
Statement statement = null;
try {
long start = System.currentTimeMillis();
try {
if(log.isLoggable(Level.FINEST)){
log.finest("Processing: "+query);
}
statement = getConn().createStatement();
statement.executeUpdate(query);
} catch (Exception e) {
if(log.isLoggable(Level.FINEST)){
log.log(Level.SEVERE, "Failed to process query: "
+ query, e);
}else{
String reportQuery = query.length() > MAX_CHARS_DISPLAY ? query.substring(0,MAX_CHARS_DISPLAY)+"..." : query;
log.log(Level.SEVERE, "Failed to process query: "
+ reportQuery , e);
}
}finally{
if(statement != null){
try {
statement.close();
} catch (SQLException e) {
log.log(Level.SEVERE,"Failed to close statement: ",e);
}
}
}
long end = System.currentTimeMillis();
return true;
}finally{
if(statement != null){
try {
statement.close();
} catch (SQLException e) {
log.log(Level.SEVERE,"Failed to close statement: ",e);
}
}
}
}
return false;
}
謝謝約翰。它確實解決了我的問題。 –