使用J2ssh jar发现内存异常
问题描述:
我们在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的方法内存如此以避免内存溢出异常?
答
你应该尝试关闭会话后释放会议和SSH对象,
这样的catch块后,
finally {
session = null;
ssh = null;
}
是内存不足不仅关系到这个代码?还可以有其他优化以及w.r.t.关闭连接,结果集等。有没有一个堆栈跟踪或证据这是根本原因? – JoseK