alibaba / transmittable-thread-local

📌 a missing Java std lib(simple & 0-dependency) for framework/middleware, provide an enhanced InheritableThreadLocal that transmits values between threads even using thread pooling components.
https://github.com/alibaba/transmittable-thread-local
Apache License 2.0
7.35k stars 1.67k forks source link

TTL 在ThreadPoolExecutor传递错误(openJ9 agent使用方式) #647

Open orangewest opened 1 month ago

orangewest commented 1 month ago

日志框架logback,修改了底层MDC的实现,改用TTL image 启动参数增加agent,调用请求发现ThreadPoolExecutor传递重复 代码如下: image image 日志如下: image 下面的没有从主线程复制 TTL版本:2.14.5 jdk8

oldratlee commented 1 month ago

@orangewest

上面说明的是 日志/MDC的问题(原因可能是 日志/MDC的使用或实现):


另外,请提供一个 极简、可运行、复现问题的 代码Demo工程。

推荐提供成一个单独的工程(GitHub repo)。这样可以:

orangewest commented 1 month ago

@oldratlee
demo地址 https://github.com/orangewest/ttl-demo 启动参数 image 代码 image image 运行结果 image image

jakejakeho commented 1 month ago

https://github.com/orangewest/ttl-demo/pull/1 image 應該是因為沒有用TtlRunnable.get() image

orangewest commented 1 month ago

@jakejakeho 使用是agent的方式,是不需要使用TtlRunnable包装的,Completablefuture里面的ForkJoinPool就没有问题。不使用agent直接用ttl包装Executor也没有问题。

orangewest commented 1 month ago

@oldratlee 大概知道是什么问题了,我用的jdk是openj9,换成openjdk就没问题了,不知道什么原因,ThreadPoolExecutor这个类没有加载,所以没有被增强。 image 但是里面的内部类加载了。 使用arthars jad命令后,才会重新触发增强。