0

我们在 webapp 中使用 j2ssh jar(j2ssh 是用于连接 Secured Shell 的外部 jar)。webapp 在 weblogic 服务器中运行。

我这样打开连接

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内存这样避免内存溢出异常?

4

1 回答 1

1

您应该在关闭会话后尝试释放会话ssh对象,

像这样在 catch 块之后,

finally {
 session = null;   
 ssh = null;
}
于 2011-10-04T05:56:37.173 回答