2

我正在开发一个使用 JTOpen ProgramCall 类 (com.ibm.as400.access.ProgramCall) 调用 IBM i (AS/400) 上的程序的 Web 应用程序(在 Tomcat 上运行)。我的问题是程序调用需要 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());
}
4

1 回答 1

3

好吧,又过了几个小时,我找到了解决方案。显然,最初的开发人员socket timeout在 JDBC 连接字符串中添加了一个参数 - 只需删除该参数即可,默认值为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();

:\

于 2016-04-04T21:49:27.143 回答