[slf4j-dev] MDC works with twitter scala Future but not CompletableFuture
Dean Hiller
dhiller at twitter.com
Thu Mar 22 15:38:43 CET 2018
unfortunately, there is no Local.java at this point BUT hopefully this
stackoverflow question explains how MDC is broken across CompletableFuture
but works fine for twitter Future
https://stackoverflow.com/questions/37933713/does-completablefuture-have-a-corresponding-local-context
NOTE: We swap the MDC with one depending on Local.scala instead of
ThreadLocal(threadlocal breaks since many threads execute 1 request when
using Future or CompletableFuture).
thanks,
Dean
On Thu, Mar 22, 2018 at 8:18 AM, Ceki <ceki at qos.ch> wrote:
>
>
> Hello Dean,
>
> What is Local.java ? Do you mean thread local? Please show an example of
> what you would like to happen.
>
> Best regards,
> --
> Ceki
>
>
>
> On 22.03.2018 14:51, Dean Hiller wrote:
>
>> Has anyone requested the jdk to add Local.java to CompletableFuture.java
>> so that context can be transferred through the .thenApply and .thenCompose
>> methods. ie. can we make MDC work in java-land with CompletableFutures?
>> (it works in scala land with twitter scala Future by swapping the MDC out
>> for the below thing I describe)
>>
>> let me go into more detail here. We use twitter Future.scala which knows
>> about Local.scala and Local.scala "acts" like a ThreadLocal. I say acts
>> because when you do future.map/flatMap(in java that is
>> thenApply/thenCompose), it transfers the threadlocal through to the next
>> executing function.
>>
>> soooo, long story short, in twitter servers, I can say
>> MDC.put("requestId", someRequestId) and it works over the .map/.flatMap.
>> This is not possible in java!!!!! ahhhhh....
>>
>> and I wrote a whole webserver in java with CompletableFutures before I
>> found this out https://github.com/deanhiller/webpieces
>>
>> ps. their response was that it would be a global. Sure, but I am
>> practical and it solves a huge many platform problems like MDC, and some in
>> my server where I don't know the customers code(and I had to hack around
>> not having a Local type thing available :( ).
>>
>> Another reason they elude to is some methods they don't know how to
>> handle Local in those cases(yup, well scala had the same thing but it
>> managed to implement it because it was too important and now java is behind
>> :( ).
>>
>> Anyways, it would be nice if others spoke up before they realize they
>> need it for the MDC to keep working.
>>
>> thanks,
>> Dean
>>
>>
>>
>> _______________________________________________
>> slf4j-dev mailing list
>> slf4j-dev at qos.ch
>> http://mailman.qos.ch/mailman/listinfo/slf4j-dev
>>
>>
> --
> --
> Ceki Gülcü
> _______________________________________________
> slf4j-dev mailing list
> slf4j-dev at qos.ch
> http://mailman.qos.ch/mailman/listinfo/slf4j-dev
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.qos.ch/pipermail/slf4j-dev/attachments/20180322/f499365c/attachment.html>
More information about the slf4j-dev
mailing list