java - java.util.concurrent.TimeoutException: 状态 200 后为空好吗?
问题描述
我目前正在开发一个 Java 11 Spring Boot 应用程序。在 CompletableFuture 中,我正在向 Web 服务发送大量 REST 请求。只有其中一个(似乎是随机的)会导致 TimeoutException,尽管它之后是在日志记录中收到的成功状态 200 OK 响应。在(匿名)日志条目之后:
[Thread-6] INFO n.d.b.a.b.i.RESTInterceptor - Request : <url value>?code=abcd&begindatum=2018-10-01&einddatum=2018-10-02
[http-nio-8080-exec-1] ERROR o.a.c.c.C.[.[.[.[dispatcherServlet] - Servlet.service() for servlet [dispatcherServlet] in context with path [/xxx] threw exception [Request processing failed; nested exception is java.util.concurrent.CompletionException: java.util.concurrent.TimeoutException] with root cause
java.util.concurrent.TimeoutException: null
at java.base/java.util.concurrent.CompletableFuture$Timeout.run(CompletableFuture.java:2792)
at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515)
at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
at java.base/java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:304)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
at java.base/java.lang.Thread.run(Thread.java:834)
[Thread-6] DEBUG n.d.b.a.b.i.RESTInterceptor - Response statuscode : 200 OK
[Thread-6] DEBUG n.d.b.a.b.i.RESTInterceptor - Response headers : [X-Application-Context:"yyyy", Cache-Control:"no-cache, no-store, max-age=0, must-revalidate", Pragma:"no-cache", Expires:"0", Server:"CD", X-Powered-By:"Unknown", Content-Type:"application/json;charset=UTF-8", Date:"Tue, 06 Apr 2021 15:23:16 GMT", Connection:"close", X-Frame-Options:"SAMEORIGIN", X-XSS-Protection:"1;mode=block", X-Content-Type-Options:"nosniff"]
[Thread-6] INFO n.d.b.a.b.i.RESTInterceptor - Response : [{"begindatum":"1993-01-01","id":"aaaaa","vanInstellingserkenningId":"bbbbb","naarInstellingserkenningId":"ccccc","soort":"HIERARCHISCH","naarInstellingserkenning":{"id":"ddddd","type":"ERKENDE_ONDERWIJSINSTELLING","code":"abcd"},"vanInstellingserkenning":{"id":"kkkk","type":"BEVOEGD_GEZAG","code":"12345"}}]
有没有人有同样的经历?我看不出成功完成的请求和“失败”的请求有什么区别。
解决方案
After deeper analysis of the problem I finally found out that the TimeoutException is thrown from another Future's handling, elsewhere in the application. The confusion I had that the handling of futures (asynchronous tasks, each in their own Thread) is not what it looks like in a log-file. The shown TimeoutException in the log-snippet is not thrown in the request-response interaction that is shown. Sorry for the confusion, but maybe others may be helped by this answer.
推荐阅读
- javascript - 异步查询选择器访问
- c++ - 难以理解的 с++ 编译器行为
- c++ - stbi_load() 对读取图片的像素数有限制吗
- dart - 当我使用 Aquedate dart 时无法识别 Pub
- c++ - 调用参数作为对 C++ 中未知边界数组的引用
- scala - 转换为 RDD 失败
- flutter - 颤振/飞镖,为什么要设置两次静态字段?
- ios - 在 ios 构建 react-native 期间出现错误“Command PhaseScriptExecution failed with a nonzero exit code in FBRectNativeSpec”
- azure-aks - AKS 中的 Deployemnt 超时错误和端点卡在“正在转换”状态
- reactjs - 未捕获的错误:无法添加节点 1,因为具有该 ID 的节点已在 Store 中