This is in regards to shell mode. I wish to be able to optimize performance, mainly in regards to receiving data back from the output stream. This is code I have cobbled together from examples. It reads both STDIN and STDERR. I assume the only way to optimize would be to decrease the thread wait time on reading from the channels. But, maybe someone has done performance optimization and has some insights that I may be missing.
Code snippet: out = channel.getOutputStream(); in = channel.getInputStream(); err = channel.getExtInputStream(); ByteArrayOutputStream bos = new ByteArrayOutputStream(); out.write(command.getBytes()); out.flush(); . . . private static String send(InputStream in, InputStream err, byte[] buffer, ByteArrayOutputStream bos, ChannelShell channel){ int exitStatus = 0; try { final long endTime = System.currentTimeMillis() + TIMEOUT; while (System.currentTimeMillis() < endTime) { while (in.available() > 0) { int count = in.read(buffer, 0, DEFAULT_BUFFER_SIZE); if (count >= 0) { bos.write(buffer, 0, count); } else { break; } } while (err.available() > 0) { int count = err.read(buffer, 0, DEFAULT_BUFFER_SIZE); if (count >= 0) { bos.write(buffer, 0, count); } else { break; } } if (channel.isClosed()) { exitStatus = channel.getExitStatus(); break; } try { //Thread.sleep(POLL_TIMEOUT); Thread.sleep(1000); } catch (InterruptedException e) { //("Ignoring interrupt."); } } } catch (IOException ioe) { // TODO: Add catch code ioe.printStackTrace(); } bos.reset(); return bos.toString();; } Also, can these affect performance: session.connect(3 * 1000); // making a connection with timeout. channel.connect(3 * 1000); TIA! ------------------------------------------------------------------------------ The ultimate all-in-one performance toolkit: Intel(R) Parallel Studio XE: Pinpoint memory and threading errors before they happen. Find and fix more than 250 security defects in the development cycle. Locate bottlenecks in serial and parallel code that limit performance. http://p.sf.net/sfu/intel-dev2devfeb _______________________________________________ JSch-users mailing list JSch-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/jsch-users