Am 27.09.2018 um 12:48 schrieb kumar saurabh:
Hi,

I am working on microservices stack and using correlation id (Unique request id) generated via nginx to log into each microservice logs. I am using MDC for extracting this from request header in OncePerRequestFilter in java.

One of the microservice then use java thread executor framework and then call other microservices.

Can using MDC with executor (java thread pool) mess up due to thread re use? Is it possible that I get either empty MDC context or incorrect context due to thread reuse?

Yes, you can get whatever MDC was left in the pool.
This could be an empty MDC (in those cases where some other thread wasn't for microservices but for something else), or the MDC of a previous microservice.

In general, whenever you start processing for a request in a thread, you need to set up the MDC so that it reflects the request it is working for. That's not just for ThreadPool, but for any thread, e.g. Swing workers and such.

(I am pretty unconvinced that thread pools are a great idea. Essentially you need to wipe all thread-local storage before you can reuse a thread from the pool, and I'm somewhat sceptical that this is still worth it.)

Regards,
Jo
_______________________________________________
slf4j-user mailing list
slf4j-user@qos.ch
http://mailman.qos.ch/mailman/listinfo/slf4j-user

Reply via email to