Skip to content
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

嵌入Thread调用的bug #70

Closed
aftersss opened this issue Nov 13, 2016 · 5 comments
Closed

嵌入Thread调用的bug #70

aftersss opened this issue Nov 13, 2016 · 5 comments
Assignees
Labels
🐞 bug Something isn't working
Milestone

Comments

@aftersss
Copy link

aftersss commented Nov 13, 2016

运行以下代码:

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是正常的。

@oldratlee
Copy link
Member

@aftersss 收到,我看看

@oldratlee
Copy link
Member

oldratlee commented Nov 14, 2016

@aftersss 修复在进行中。转成了复现问题的UT,参见提交: bbd4f9e

如果急着解决,先给一个bypass的方法:

new Thread(){
    public void run(){
        // 这里补一行 get
        tl1.get();

        TtlRunnable runnable = TtlRunnable.get(new Runnable() {
            @Override
            public void run() {
                System.out.println("pool tl1-2:"+tl1.get());
            }
        },false,false);
        executorService.submit(runnable);
    }
}.start();

oldratlee added a commit that referenced this issue Nov 14, 2016
@oldratlee
Copy link
Member

oldratlee commented Nov 14, 2016

问题已经修复,参见 提交

  1. c5ed61a
  2. 87a02ab

发布了版本 2.1.0这里是release log, Maven依赖:

<dependency>
    <groupId>com.alibaba</groupId>
    <artifactId>transmittable-thread-local</artifactId>
    <version>2.1.0</version>
</dependency>

@aftersss 非常赞 👍

嵌套ThreadExecutorServcie这样的使用方式,
之前的UT没有覆盖到,到现在为止的使用中也没有触发这个问题。

非常感谢你的问题反馈!!

@oldratlee oldratlee modified the milestone: 2.1.0 Nov 14, 2016
@oldratlee oldratlee added the 🐞 bug Something isn't working label Nov 14, 2016
@oldratlee oldratlee self-assigned this Nov 14, 2016
oldratlee added a commit that referenced this issue Nov 14, 2016
@aftersss
Copy link
Author

OK,谢谢

@oldratlee
Copy link
Member

oldratlee commented Nov 15, 2016

@aftersss 问一下你在什么场景/需求下使用ttl,哪个公司/项目。收集了解一下用户 :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐞 bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants