安博靖宁 2019-08-26 19:17 采纳率: 0%
浏览 3376

java.net.SocketTimeoutException: Read timed out

1、每次在进行批作业的时候,会构建http的请求

     * 定时发送监控信息到质检端
     *
     * @return
     */
    @Scheduled(fixedRate = 60000*5)
    public String sendMonitorInfo() throws IOException {
        List<Map> info = monitorService.getMonitorInfo();
        logger.debug("monitor info{}",info);
        String result = HttpUtil.doPost(sendURL,JSONArray.toJSONString(info),10000,10000);
        logger.debug("send monitor result{}",result);
        return result;
    }

2、在请求构建完成之后,会发送请求

            //发送请求
            HttpResponse response = httpClient.execute(post);
            HttpEntity entityReaponse = response.getEntity();
            if (entityReaponse != null) {
                inputStream = entityReaponse.getContent();
                //转换为字节输入流
                BufferedReader br = new BufferedReader(new InputStreamReader(inputStream, Consts.UTF_8));
                while ((body = br.readLine()) != null) {
                    result.append(body);
                }
            }
        } catch (Throwable e) {
            e.printStackTrace();
            logger.error("http post error:",e);
            return null;
        } finally {
            if (inputStream != null) {
                try {
                    inputStream.close();
                } catch (IOException e) {
                    e.printStackTrace();
                    return null;
                }
            }
        }

这个错应该是在 while ((body = br.readLine()) != null)方法中的,但是不知道为什么
debug的时候就显示read time out
求大神帮忙解答一下

  • 写回答

1条回答

  • threenewbee 2019-08-26 22:02
    关注

    String result = HttpUtil.doPost(sendURL,JSONArray.toJSONString(info),10000,10000);

    这里的10000可能是超时的时间,设置高一些看看

    评论

报告相同问题?

悬赏问题

  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?