我尝试将超时设置为休息模板,如下面的1和2.它是随机工作的,有时读取时间在9秒后失败但有时我会在10-11秒后得到响应。是否有任何具体原因导致超时不能持续工作下载文件。我正在下载最大1.5MB的文件
1.RestTemplate srestTemplate = new RestTemplate(); HttpComponentsClientHttpRequestFactory factory = new HttpComponentsClientHttpRequestFactory(); factory.setReadTimeout(9000); factory.setConnectTimeout(9000); factory.setConnectionRequestTimeout(9000); srestTemplate.setRequestFactory(工厂); 2.RequestConfig config = RequestConfig.custom() .setSocketTimeout(9000) .setConnectTimeout(9000) .setConnectionRequestTimeout(9000).build();
CloseableHttpClient httpClient = HttpClients.custom().setConnectionManager(connectionManager)
.setDefaultRequestConfig(config).build();
restTemplate = new RestTemplate(new HttpComponentsClientHttpRequestFactory(httpClient));