2

I recently found myself having the same problem Lukasz describes here. While the answer to this question proved helpful and ultimately helped me to solve my problem I was hoping someone may know why ThreadPoolTaskExecutor does not properly handle MODE_INHERITABLETHREADLOCAL? Is this problem isolated to ThreadPoolTaskExecutor?

Thanks! Ryan

Community
  • 1
  • 1

1 Answers1

3

Ok, according to this post in the spring source forum, the value in child threads is set from the parent thread only when the thread is created. If you have a pool of threads for reuse, the value is not set again unless you change it.

I quote from the post

You seem to want the context of the calling thread (which invokes the executor) to be used instead of the context of the creating thread. This isn't the same as using an inherited thread-local, so that's not the way to go. You would be better to set the context explicitly yourself, or customize the executor implementation to do so.

ElderMael
  • 7,000
  • 5
  • 34
  • 53