0

I have a classA which is running on Tomcat thread. ClassA is maintaining a set of MDC key-values pairs.

As the ClassA is executed, MDC.getCopyOfContextMap() returns (A="a", B="b", C="c")

Now, ClassA calls classB which is running on Hystrix thread.

When we enter ClassB, MDC from ClassA is copied and MDC.getCopyOfContextMap() returns (A="a", B="b", C="c").

ClassB sets a value of a variable X into MDC. MDC.put("X", String.valueOf("someVal")) When still inside ClassB, MDC.getCopyOfContextMap() returns (A="a", B="b", C="c", X="someVal").

ClassA receives the MDC and tries to access the variable X.

MDC.get(X)

But it gets it as null becauseMDC.getCopyOfContextMap() returns (A="a", B="b", C="c").

Any suggestions why MDC is not transferred from Hystrix thread to tomcat thread?

P_user526
  • 65
  • 3
  • 11

2 Answers2

0

String.valueOf("someVal")

I think , you have to use variable instead of "someValue" String.valueOf(variable)

0

MDC works in a way similar to how ThreadLocal works. It is linked to the current thread and does not get automatically transferred in case of threadPools (Hystrix also uses threadPool).

So you need to copy MDC from your main thread to hystrix thread (not your use case though) and from hystrix thread to main thread.

You can use HystrixHook to accomplish this.

Have a look at this blog

FlapPy
  • 160
  • 11