为了安全起见,我是否需要增加等待时间才能获得 restful 服务响应?

do I need to add wait time to get restful service response for safety?

我正在使用 httpclient 访问 rest 服务。我正在从休息服务中获取 json 数据,并且正在对其进行进一步处理。但是,如果由于某种原因,我无法快速获得响应,而主线程没有等待响应就继续执行怎么办?

我需要处理这种情况吗?

我将休息服务称为

            DefaultHttpClient client=new CustomHttpClient();
            HttpGet reqG;
            HttpResponse respG=null;
            HttpEntity entity;
            reqG= new HttpGet(url);
            respG= client.execute(reqG);
            entity = respG.getEntity();
            InputStream is=entity.getContent();

我需要在 client.execute(reqG) 之后添加 Thread.sleep() 或者 有没有更好的方法呢?

请指教

Q. main thread continue its execution without waiting for response?

A. No, the main thread will not continue its execution until some response comes.

如果您的服务耗时过长,则可能是请求超时。