gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-01 11:11:10 26 4
gpt4 key购买 nike

我正在使用 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.

如果您的服务花费太多时间,则可能会出现请求超时。

关于java - 为了安全起见,我是否需要增加等待时间才能获得安静的服务响应?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32352506/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com