Java Ganymed ssh-如何设置超时以在execCommand花费更多时间时关闭会话

Java Ganymed ssh-如何设置超时以在execCommand花费更多时间时关闭会话,java,session,ssh,Java,Session,Ssh,我正在使用Ganymed ssh远程获取日志详细信息。下面是我的代码。有时,stdout返回的数据非常庞大,因此需要更多的时间才能返回。如果标准输出在1分钟内没有返回,我想关闭会话。如何设置会话自动关闭的超时时间是否超过1分钟 Connection conn = new Connection(hostname); conn.connect(); boolean isAuthenticated = conn.authenticateWithPassword(username, password);

我正在使用Ganymed ssh远程获取日志详细信息。下面是我的代码。有时,stdout返回的数据非常庞大,因此需要更多的时间才能返回。如果标准输出在1分钟内没有返回,我想关闭会话。如何设置会话自动关闭的超时时间是否超过1分钟

Connection conn = new Connection(hostname);
conn.connect();
boolean isAuthenticated = conn.authenticateWithPassword(username, password);
if (isAuthenticated == false)
   throw new IOException("Authentication failed.");
Session session = conn.openSession();
session.execCommand("grep traceid trace.log");
InputStream stdout = new StreamGobbler(session.getStdout());
BufferedReader br = new BufferedReader(new InputStreamReader(stdout));
while (true)
     {
         String line = br.readLine();
         if (line == null)
              break;
         System.out.println(line);
      }
System.out.println("ExitCode: " + session.getExitStatus());
session.close();
conn.close();
你可以使用这个方法 或会话类的方法。 两者都需要超时参数