2011-10-04 63 views
0

我們在webapp中使用j2ssh jar(j2ssh是一個用於連接Secured Shell的外部jar)。webapp在weblogic服務器上運行。使用J2ssh jar發現內存異常

我開這樣的

SshClient ssh = new SshClient(); 
SessionChannelClient session=null; 
session = ssh.openSessionChannel(); 

內部的連接finally塊我關閉會話這樣。

finally 
{ 
    System.out.println("disconnecting from ssh"); 
    try 
{ 
    session.close(); 
} 
catch(IOException ioe) 
{ 
    theOutput = ioe.getMessage(); 
    System.out.println("IOException="+ioe); 
} 
} 

我的疑問是我正確關閉連接?它會清除Weblogic堆棧,因爲我們越來越頻繁地抱怨用戶由於內存溢出而收到異常,這基本上意味着垃圾回收沒有正常發生。一旦我們重新啓動服務器,它就會自動解決。是否有定期清除weblogic的方法內存如此以避免內存溢出異常?

+0

是內存不足不僅關係到這個代碼?還可以有其他優化以及w.r.t.關閉連接,結果集等。有沒有一個堆棧跟蹤或證據這是根本原因? – JoseK

回答

1

你應該嘗試關閉會話後釋放會議SSH對象,

這樣的catch塊後,

finally { 
session = null; 
ssh = null; 
}