Hello

with @Asynchronous it can be tricky and highly container dependent but if
you migrate to ManagedExecutor service (it is quite trivial to do a cdi
interceptor implementing @Async to make it smoother) then you can submit
ManagedTask which can have task listener which would allow when creating
the task to submit the current MDC and propagate it

Should still have a sample doing it if you need help going that way


Romain Manni-Bucau
@rmannibucau <https://twitter.com/rmannibucau> |  Blog
<https://blog-rmannibucau.rhcloud.com> | Old Blog
<http://rmannibucau.wordpress.com> | Github <https://github.com/rmannibucau> |
LinkedIn <https://www.linkedin.com/in/rmannibucau> | JavaEE Factory
<https://javaeefactory-rmannibucau.rhcloud.com>

2017-01-25 11:56 GMT+01:00 cocorossello <cocorosse...@gmail.com>:

> Hi,
>
> I'm using logback's MDC to setup some logging info accross my application
> (jsessionid and other stuff). Our application uses lots of @Asynchronous
> methods. Since logback 1.1.3 MDC context is not propagated to child
> threads.
>
> Is there any way to customise the asynchronous thread pool executor so I
> can
> propagate manually the context as logback docs says?
>
> /MDC And Managed Threads
>
> A copy of the mapped diagnostic context can not always be inherited by
> worker threads from the initiating thread. This is the case when
> java.util.concurrent.Executors is used for thread management. For instance,
> newCachedThreadPool method creates a ThreadPoolExecutor and like other
> thread pooling code, it has intricate thread creation logic.
>
> In such cases, it is recommended that MDC.getCopyOfContextMap() is invoked
> on the original (master) thread before submitting a task to the executor.
> When the task runs, as its first action, it should invoke
> MDC.setContextMapValues() to associate the stored copy of the original MDC
> values with the new Executor managed thread./
>
> (or should I just forget MDC and think of another "context" mechanism?)
>
>
>
> --
> View this message in context: http://tomee-openejb.979440.
> n4.nabble.com/MDC-and-Asynchronous-tp4680927.html
> Sent from the TomEE Users mailing list archive at Nabble.com.
>

Reply via email to