我正在开发一个Web应用程序(在Tomcat上运行),该Web应用程序使用JTOpen ProgramCall类(com.ibm.as400.access.ProgramCall)调用IBM i(AS / 400)上的程序。我的问题是,响应时间超过30秒的程序调用触发了java.net.SocketTimeoutException: Read timed out exception
。
此类有一个setTimeout()
方法可用,但似乎对套接字超时没有影响。我还检查了Tomcat的配置,没有发现任何会导致此问题的内容。
有谁知道改变这种实现超时的方法?
码:
pgmCall.setProgram(getCompleteName(), parmList);
initializeAS400TextParameters();
// Run the AS/400 program.
try {
Trace.setTraceDiagnosticOn(true);
Trace.setTraceInformationOn(true);
Trace.setTraceWarningOn(true);
Trace.setTraceErrorOn(true);
Trace.setTraceDatastreamOn(true);
if (pgmCall.run() != true) {
messageList = pgmCall.getMessageList();
for (int i = 0; i < messageList.length; i++) {
log.debug("Error Message " + i + " " + messageList[i]);
}
setCompletionMsg("Program call failed.");
log.debug("442 Program call failed.");
return false;
} else {
messageList = pgmCall.getMessageList();
for (int i = 0; i < messageList.length; i++) {
log.debug("Success Message " + i + " " + messageList[i]);
}
setCompletionMsg("Program called ok.");
log.debug("452 Program called ok.");
return true;
}
} catch (Exception e) {
// This is where the timeout exception is thrown
log.debug("Error Running Program: " + e.getMessage() + " " + e.getLocalizedMessage());
setCompletionMsg(e.getMessage());
}
最佳答案
好了,几个小时后,我找到了解决方案。显然,原始开发人员在JDBC连接字符串中添加了socket timeout
参数-只需删除该参数即可完成操作,因为默认值是0
或无限超时。
之前:String connectionStr = "jdbc:as400://" + systemInfo.getIPAddress() + ":1527" + ";naming=system;socket timeout=30000;thread used=false;errors=full;prompt=false;date format=iso;block size=128;transaction isolation=none;user=" + systemInfo.getUserName() + ";password=" + systemInfo.getPassword();
后:String connectionStr = "jdbc:as400://" + systemInfo.getIPAddress() + ":1527" + ";naming=system;thread used=false;errors=full;prompt=false;date format=iso;block size=128;transaction isolation=none;user=" + systemInfo.getUserName() + ";password=" + systemInfo.getPassword();
:\
关于java - JTOpen ProgramCall套接字超时,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/36362402/