Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
303 views
in Technique[技术] by (71.8m points)

java - ExecutorService often triggers okhttp timeout when I try to use it with awaitTermination

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...