I use something like this in order to run an ExecutorService
and await termination of the task
ExecutorService taskExecutor = Executors.newFixedThreadPool(1);
while(...) {
taskExecutor.execute(new MyTask());
}
taskExecutor.shutdown();
try {
taskExecutor.awaitTermination(Long.MAX_VALUE, TimeUnit.NANOSECONDS);
} catch (InterruptedException e) {
...
}
Sometimes this works as supposed but very often the execution of the same operation is interrupted with this error
System.err: at com.android.okhttp.okio.Timeout.throwIfReached(Timeout.java:147)
System.err: at com.android.okhttp.okio.Okio$1.write(Okio.java:75)
System.err: at com.android.okhttp.okio.AsyncTimeout$1.write(AsyncTimeout.java:157)
System.err: at com.android.okhttp.okio.RealBufferedSink.flush(RealBufferedSink.java:222)
System.err: at com.android.okhttp.internal.http.Http1xStream.finishRequest(Http1xStream.java:163)
System.err: at com.android.okhttp.internal.http.HttpEngine.readNetworkResponse(HttpEngine.java:748)
System.err: at com.android.okhttp.internal.http.HttpEngine.readResponse(HttpEngine.java:622)
System.err: at com.android.okhttp.internal.huc.HttpURLConnectionImpl.execute(HttpURLConnectionImpl.java:475)
System.err: at com.android.okhttp.internal.huc.HttpURLConnectionImpl.getResponse(HttpURLConnectionImpl.java:411)
System.err: at com.android.okhttp.internal.huc.HttpURLConnectionImpl.getResponseCode(HttpURLConnectionImpl.java:542)
System.err: at com.android.okhttp.internal.huc.DelegatingHttpsURLConnection.getResponseCode(DelegatingHttpsURLConnection.java:106)
System.err: at com.android.okhttp.internal.huc.HttpsURLConnectionImpl.getResponseCode(HttpsURLConnectionImpl.java:30)
at
myConnection.getResponseCode()
where myConnection
is a HttpURLConnection
and the method is called aftermyConnection.connect()
question from:
https://stackoverflow.com/questions/65921196/executorservice-often-triggers-okhttp-timeout-when-i-try-to-use-it-with-awaitter 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…