我对SSHJ和多线程有疑问。我有一个使用SSHJ在远程服务器上使用SSHJ SSHExec类执行命令的类,它是Threads的扩展。我这样做是因为某些远程命令可能需要一段时间才能运行,我想并行运行它们,因为它们不会相互影响。
所以我的设置中有class_A,可以启动class_B的多个版本,这是执行SSH命令的程序。当我将class_A配置为仅启动class_B的一个实例时,一切正常。但是,当我将class_A配置为启动多个class_B的一个实例时,它会因以下错误而失败。
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)
在线程中启动多个SSHExec会话是否有问题?如果不是我可能做错了什么?