这是我的配置:
httpClient = new OkHttpClient.Builder()
.callTimeout(Duration.ofSeconds(60))
.connectTimeout(Duration.ofSeconds(60))
.readTimeout(Duration.ofSeconds(60))
.writeTimeout(Duration.ofSeconds(60))
.build();
我有一个使用此客户端的多线程进程。运行几秒钟后,我得到以下错误信息:
java.net.SocketTimeoutException: timeout
at okio.Okio$4.newTimeoutException(Okio.java:232)
at okio.AsyncTimeout.exit(AsyncTimeout.java:286)
at okio.AsyncTimeout$2.read(AsyncTimeout.java:241)
at okio.RealBufferedSource.indexOf(RealBufferedSource.java:358)
如果我将超时时间设置为60秒,那怎么可能会发生这种情况?
编辑:
即使添加自定义调度程序也没有帮助:
Dispatcher dispatcher = new Dispatcher();
dispatcher.setMaxRequests(Integer.MAX_VALUE);
dispatcher.setMaxRequestsPerHost(Integer.MAX_VALUE);
技术细节:
与我之前所说的相反,我正在Linux机器上运行客户端和服务器:
客户端机器: net.ipv4.tcp_keepalive_time = 7200
服务器机器: net.ipv4.tcp_keepalive_time = 7200
sysctl net.inet.tcp
的输出,我认为这是您的代码遇到超时异常的原因。如果不是,请说明服务器正在执行什么操作(难道 Flask 不是 Python 的东西吗?)。 - Karol Dowbecki