我使用JSch 0.1.50爲我的CI Jenkins插件建立到遠程服務器的連接。假設我想在這裏使用session.connect(60000);
在超時60秒:JSch會話超時限制
Session session = null;
try {
JSch jsch = new JSch();
if (rsaIdentity != null && !rsaIdentity.equals("")) {
jsch.addIdentity(rsaIdentity.trim());
}
session = jsch.getSession(serverLogin, serverHost, Integer.parseInt(serverPort));
session.setPassword(getDescriptor().getOpenPassword(encryptedPasswordString));
session.setConfig("StrictHostKeyChecking", "no"); // not use RSA key
int timeOut = Integer.parseInt(getDescriptor().getConnectionTimeOut());
session.connect(60000);
} catch (SocketTimeoutException e) {
logger.error(e.getMessage());
return false;
} catch (JSchException e) {
logger.error(e.getMessage());
return false;
}
但是在這個代碼的連接在執行過程中事實很慢服務器我面臨的超時Exception
在約20秒每次:
2016-01-25 13:15:55.982 [INFO] Connecting to server: devsrv26:22 as [user] ...
2016-01-25 13:16:16.991 [ERROR] java.net.ConnectException: Connection timed out: connect
2016-01-25 13:16:16.992 com.jcraft.jsch.JSchException: java.net.ConnectException: Connection timed out: connect
2016-01-25 13:16:16.992 at com.jcraft.jsch.Util.createSocket(Util.java:389)
2016-01-25 13:16:16.993 at com.jcraft.jsch.Session.connect(Session.java:215)
2016-01-25 13:16:16.993 at com.mycomp.jenkins.MyPlugin.perform(MyPlugin.java:225)
76991-55982 = 21008毫秒
有誰知道什麼是這20秒計算的逾原因?
的問題是從服務器端IP配置。該服務器具有配置了連接超時的DMZ IP地址。 –