Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/375.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/107.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 网络请求超时或网络丢失或网络速度缓慢,无法在codenameone中正确处理_Java_Ios_Codenameone - Fatal编程技术网

Java 网络请求超时或网络丢失或网络速度缓慢,无法在codenameone中正确处理

Java 网络请求超时或网络丢失或网络速度缓慢,无法在codenameone中正确处理,java,ios,codenameone,Java,Ios,Codenameone,我试着按如下顺序逐个调用web服务。一旦所有web服务成功运行,任务就结束了。如果没有,则必须向用户显示警报 代码: Dialog progressDialog=ComponentUtils.getFormattedDialog(new Dialog()); progressDialog.showModeless(); 布尔allDone=true; 对于(int i=0;iCodename One中的Timeout当前仅限于连接超时,不适用于读取超时,因此一旦建立连接,它将持续。您可以使用网络

我试着按如下顺序逐个调用web服务。一旦所有web服务成功运行,任务就结束了。如果没有,则必须向用户显示警报

代码:

Dialog progressDialog=ComponentUtils.getFormattedDialog(new Dialog());
progressDialog.showModeless();
布尔allDone=true;

对于(int i=0;iCodename One中的Timeout当前仅限于连接超时,不适用于读取超时,因此一旦建立连接,它将持续。您可以使用
网络管理器上的进度侦听器来检测此类情况并终止连接。

@Shai感谢您的建议。实际上,我有自己的进度条没有操作。那么如何处理这个问题呢?在这个超时的情况下,handleException或handleErrorResponseCode中没有抛出错误。超时是有问题的,因为它在不同的操作系统中表现非常不同
Dialog progressDialog = ComponentUtils.getFormattedDialog(new Dialog());
progressDialog.showModeless();

boolean allDone = true;

for(int i=0;i<serviceList.size();i++){
    String serviceUrl = serviceList.get(i);
    boolean service = getServiceResponse(serviceUrl);
    if(service==false){
        progressDialog.dispose();
        allDone = false;
        break;
    }
}

if(allDone){
    progressDialog.dispose();
    Dialog.show("SUCCESS","Process Done","OK",null);
}
else{
    Dialog.show("FAIL","Process Failed","OK",null)
}

...


public static boolean getServiceResponse(String serviceUrl){
    boolean isSuccess = false;
    ConnectionRequest connectionRequest = new ConnectionRequest() { 
        @Override
        protected void handleErrorResponseCode(int code, String message) {
            this.kill();
            LogUtil.setErrorLog(message,page_name+ " > handleErrorResponseCode");
            isSuccess = false
        }

        @Override
        protected void handleException(Exception err) {
            this.kill();
            LogUtil.setErrorLog(err,page_name + " > handleException");
            isSuccess = false
        }

        @Override
        protected void readResponse(InputStream input)  {
            isSuccess = true
        }
    };

    connectionRequest.setUrl(serviceUrl);
    connectionRequest.setContentType("application/x-www-form-urlencoded");
    connectionRequest.setPost(true);
    connectionRequest.setDuplicateSupported(true);
    connectionRequest.setTimeout(100000);
    NetworkManager.getInstance().addToQueueAndWait(connectionRequest);

    return isSuccess;
}