2016-04-01 67 views
0

我正在使用JTOpen ProgramCall類(com.ibm.as400.access.ProgramCall)調用IBM i(AS/400)上的程序的Web應用程序(運行於Tomcat上)。我的問題是程序調用需要超過30秒才能響應,這觸發java.net.SocketTimeoutException: Read timed out exceptionJTOpen ProgramCall Socket Timeout

有一個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()); 
} 

回答

1

好,幾個小時後,我已經找到了解決方案。顯然,原始開發人員在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();

:\