Search code examples
sshweblogicstack-overflowj2ssh

Out of memory exception using J2ssh jar


We are using j2ssh jar(j2ssh is an external jar used to connect Secured Shell)in our webapp.The webapp is running in weblogic server.

I open the connection like this

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

inside the finally block I close the session like this.

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

My doubt is am I closing the connection properly? Will it clear the Weblogic stack because we are getting frequent complaints that users are getting exceptions due to memory overflow which basically means garbage collection is not happening properly.Once we restart the server it is automatically solved.Is there a way to periodically clear the weblogic memory so to avoid memory overflow exception?


Solution

  • You should try releasing the session and ssh object after closing session,

    something like this after catch block,

    finally {
     session = null;   
     ssh = null;
    }