SSHJ and multiple threads

2.5k Views Asked by At

I have a question about SSHJ and multiple threads. I have a class that uses SSHJ to execute commands on a remote server using the SSHJ SSHExec class and it is an extension of Threads. I am doing this because some of the remote commands can take a while to run, and I want to run them in parallel since they do not effect each other.

So my in my setup I have class_A that can start multiple version of class_B, which is the program that executes the SSH commands. When I configure class_A to only start one instance of class_B everything works fine. But when I configure class_A to start more then one instance of class_B it fails with the following error.

Aug 2, 2012 12:08:44 PM backup.SSHExec run
SEVERE: null
net.schmizz.sshj.transport.TransportException: Unexpected: SSH_MSG_UNIMPLEMENTED
    at net.schmizz.sshj.transport.TransportException$1.chain(TransportException.java:33)
    at net.schmizz.sshj.transport.TransportException$1.chain(TransportException.java:27)
    at net.schmizz.concurrent.Promise.deliverError(Promise.java:95)
    at net.schmizz.concurrent.Event.deliverError(Event.java:72)
    at net.schmizz.concurrent.ErrorDeliveryUtil.alertEvents(ErrorDeliveryUtil.java:34)
    at net.schmizz.sshj.transport.TransportImpl.die(TransportImpl.java:576)
    at net.schmizz.sshj.transport.Reader.run(Reader.java:79)
Caused by: net.schmizz.sshj.common.SSHException: [PROTOCOL_ERROR] Unexpected: SSH_MSG_UNIMPLEMENTED
    at net.schmizz.sshj.AbstractService.notifyUnimplemented(AbstractService.java:66)
    at net.schmizz.sshj.transport.TransportImpl.gotUnimplemented(TransportImpl.java:555)
    at net.schmizz.sshj.transport.TransportImpl.handle(TransportImpl.java:490)
    at net.schmizz.sshj.transport.Decoder.decode(Decoder.java:127)
    at net.schmizz.sshj.transport.Decoder.received(Decoder.java:195)
    at net.schmizz.sshj.transport.Reader.run(Reader.java:72)
Exception in thread "Thread-18" java.lang.NullPointerException
    at java.io.Reader.<init>(Reader.java:61)
    at java.io.InputStreamReader.<init>(InputStreamReader.java:55)
    at backup.StreamReader.run(StreamReader.java:86)
Exception in thread "Thread-17" java.lang.NullPointerException
    at java.io.Reader.<init>(Reader.java:61)
    at java.io.InputStreamReader.<init>(InputStreamReader.java:55)
    at backup.StreamReader.run(StreamReader.java:86)
Aug 2, 2012 12:08:44 PM backup.SSHExec run
SEVERE: null
net.schmizz.sshj.transport.TransportException: socket closed
    at net.schmizz.sshj.transport.TransportImpl.init(TransportImpl.java:164)
    at net.schmizz.sshj.SSHClient.onConnect(SSHClient.java:671)
    at net.schmizz.sshj.SocketClient.connect(SocketClient.java:71)
    at net.schmizz.sshj.SocketClient.connect(SocketClient.java:77)
    at net.schmizz.sshj.SocketClient.connect(SocketClient.java:103)
    at backup.SSHExec.run(SSHExec.java:73)
    at backup.SSHExec.exec(SSHExec.java:42)
    at backup.BackupExec2.copyPrevBackup(BackupExec2.java:335)
    at backup.BackupExec2.run(BackupExec2.java:164)
Caused by: java.net.SocketException: socket closed
    at java.net.SocketInputStream.socketRead0(Native Method)
    at java.net.SocketInputStream.read(SocketInputStream.java:129)
    at java.net.SocketInputStream.read(SocketInputStream.java:182)
    at net.schmizz.sshj.transport.TransportImpl.init(TransportImpl.java:158)
    ... 8 more
Exception in thread "Thread-23" java.lang.NullPointerException
    at java.io.Reader.<init>(Reader.java:61)
    at java.io.InputStreamReader.<init>(InputStreamReader.java:55)
    at backup.StreamReader.run(StreamReader.java:86)
Exception in thread "Thread-24" java.lang.NullPointerException
    at java.io.Reader.<init>(Reader.java:61)
    at java.io.InputStreamReader.<init>(InputStreamReader.java:55)
    at backup.StreamReader.run(StreamReader.java:86)

Is there a problem with starting mulitple SSHExec session in threads? If not what could I be doing wrong?

0

There are 0 best solutions below