-
Notifications
You must be signed in to change notification settings - Fork 1.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
disable Inheritable when it's not necessary and buggy(eg. has potential memory leaking problem) #100
Comments
Transmit thread local values by inheritable thread local is a potential leaking problem. A new created thread can never know how to deal with the inherited values. The transmittable thread local values should be created and cleared within a task's lifecycle. InheritableThreadLocal will leak the management of transmittable thread local values out of a task. |
Inheritable feature by using InheritableThreadLocal can be disabled by setting `com.alibaba.ttl.inheritable` to false to avoid potential leaking problem described in #100, default value is true to ensure compatible with previous versions.
Inheritable feature by using InheritableThreadLocal can be disabled by overriding `childValue` and `return null` to avoid potential leaking problem described in #100. Implementation is provided as NoInheritableTTL.
Here are some thoughts about the inheritable feature: case 1Inheritable feature in thread pooling components( case 2Whether the value should be inheritable or not can be controlled by the data owner, disable it carefully when data owner have a clear idea. disable TransmittableThreadLocal<String> transmittableThreadLocal = new TransmittableThreadLocal<String>() {
protected String childValue(String parentValue) {
return initialValue();
}
} |
- add DisableInheritableThreadFactory wrapper in TtlExecutors - add Inheritable unit test
…Local disable Inheritable feature by using InheritableThreadLocal can avoid potential leaking problem described in #100
Solved. |
为什么不直接 继承 ThreadLocal 呢? 或者可以在 构造器 增加参数- |
在业务中可以直接以 选择继承
而
要说明/解决问题,你需要给出 全场景 下的说明,比如说明出: 那么,就可以推出你的结论:『 |
The core scenario is transmit value value from the time task is created to the time task is executed, so transmitting value
new Thread
(Inheritable) maybe is not necessary and buggy(eg. has potential memory/context leaking problem).The text was updated successfully, but these errors were encountered: