Does CompletableFuture have a corresponding Local context?

后端 未结 2 2114
执念已碎
执念已碎 2021-02-06 06:26

In the olden days, we had ThreadLocal for programs to carry data along with the request path since all request processing was done on that thread and stuff like Log

2条回答
  •  难免孤独
    2021-02-06 07:05

    If you come across this, just poke the thread here http://mail.openjdk.java.net/pipermail/core-libs-dev/2017-May/047867.html

    to implement something like twitter Futures which transfer Locals (Much like ThreadLocal but transfers state).

    See the def respond() method in here and how it calls Locals.save() and Locals.restort() https://github.com/simonratner/twitter-util/blob/master/util-core/src/main/scala/com/twitter/util/Future.scala

    If Java Authors would fix this, then the MDC in logback would work across all 3rd party libraries. Until then, IT WILL NOT WORK unless you can change the 3rd party library(doubtful you can do that).

提交回复
热议问题