Closed
Description
运行以下代码:
final ExecutorService executorService = Executors.newSingleThreadExecutor();
final InheritableThreadLocal<String> tl1 = new TransmittableThreadLocal<>();
tl1.set("hello");
TtlRunnable runnable = TtlRunnable.get(new Runnable() {
@Override
public void run() {
System.out.println("pool tl1:"+tl1.get());
}
});
executorService.submit(runnable);
Thread.sleep(200);
new Thread(){
public void run(){
TtlRunnable runnable = TtlRunnable.get(new Runnable() {
@Override
public void run() {
System.out.println("pool tl1-2:"+tl1.get());
}
},false,false);
executorService.submit(runnable);
}
}.start();
输出:
pool tl1:hello
pool tl1-2:null
第二行不应该为null
,改成使用InheritableThreadLocal
是正常的。
Metadata
Metadata
Assignees
Labels
Type
Projects
Relationships
Development
No branches or pull requests
Activity
oldratlee commentedon Nov 14, 2016
@aftersss 收到,我看看
add bug #70 reproduce test case, test should fail
add bug #70 reproduce test case, test should fail
oldratlee commentedon Nov 14, 2016
@aftersss 修复在进行中。转成了复现问题的UT,参见提交: bbd4f9e
如果急着解决,先给一个bypass的方法:
fixed bug #70
oldratlee commentedon Nov 14, 2016
问题已经修复,参见 提交
发布了版本
2.1.0
,这里是release log, Maven依赖:@aftersss 非常赞 👍
嵌套
Thread
和ExecutorServcie
这样的使用方式,之前的UT没有覆盖到,到现在为止的使用中也没有触发这个问题。
非常感谢你的问题反馈!!
add bug #70 reproduce test case, test should fail
fixed bug #70
aftersss commentedon Nov 15, 2016
OK,谢谢
oldratlee commentedon Nov 15, 2016
@aftersss 问一下你在什么场景/需求下使用ttl,哪个公司/项目。收集了解一下用户 :)
1 remaining item