我最近发现自己遇到了 Lukasz 描述的同样问题 here 。虽然这个问题的答案被证明很有帮助并最终帮助我解决了我的问题,但我希望有人知道为什么 ThreadPoolTaskExecutor 不能正确处理 MODE_INHERITABLETHREADLOCAL?此问题是否与 ThreadPoolTaskExecutor 无关?
谢谢! 瑞安
最佳答案
好的,根据this post在spring源码论坛中,子线程中的值仅在创建线程时从父线程设置。如果您有一个可供重用的线程池,则除非您更改该值,否则不会再次设置该值。
我引用帖子内容
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.
关于java - Spring Security 和异步执行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13462642/