0

我已经生成了对 Web 服务的请求。我需要检查我的通话。如果在 5 秒内没有返回响应,则会再次发起请求。

伪代码:

webServiceClass 响应 = xyz.getData(); 如果在 5 秒内未获得响应 - 向 Web 服务发送另一个请求 CheckData()。这应该最多执行 5 次。

我需要在不使用线程的情况下执行此操作。

4

1 回答 1

0

尝试这样的事情(未经测试,但应该给你的想法):

final MultiThreadedHttpConnectionManager httpConnections = new MultiThreadedHttpConnectionManager();
final HttpConnectionManagerParams connParams = manager.getParams();
final HttpClient httpClient = new HttpClient(manager);
final int connectionTimeout = 5000;         
connParams.setConnectionTimeout(connectionTimeout);

    try 
    {
        // your web service call goes here
    }
    catch(ConnectTimeoutException cte)
    {   
        if (isLoggingError())
        {
            logError(cte.getMessage());
        }
    }
    catch(IOException ioe)
    {
        if (isLoggingError())
        {
            logError(ioe.getMessage());
        }
    }
    finally 
    {
        // make sure we always release the connection
        method.releaseConnection();
    }       
于 2014-10-20T17:57:10.180 回答