We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
看到使用说明中说,需要修饰Runnable和Callable方能传参,那么我这种使用,是不是意味着不修饰也能传? 还是说我理解有问题?
Runnable
Callable
class TtlTest { private static final ThreadLocal<String> TL = new TransmittableThreadLocal<>(); private static final ExecutorService pool = Executors.newFixedThreadPool(10); @Test void ttl() throws Exception { TL.set("Jay"); pool.submit(() -> { String name = TL.get(); System.err.println(name); // 也能获取到参数 }); SECONDS.sleep(2000); } }
The text was updated successfully, but these errors were encountered:
看到使用说明中说,需要修改Runnable和Callable方能传参,那么我这种使用,是不是意味着不修饰也能传?
@Dreamroute 如果不修饰,TransmittableThreadLocal的效果/功能就退化成 JDK的InheritableThreadLocal。
TransmittableThreadLocal
JDK
InheritableThreadLocal
InheritableThreadLocal的功能是你的Demo能取到参数的原因。
具体一些的说明参见项目的用户使用文档:
Java Agent
进一步系统理解或确认,请看
TTL
Sorry, something went wrong.
果然,如果提前为线程池预热,比如执行若干次pool.submit(() -> {});,那么就无法获取到值了。
pool.submit(() -> {});
oldratlee
No branches or pull requests
看到使用说明中说,需要修饰
Runnable
和Callable
方能传参,那么我这种使用,是不是意味着不修饰也能传?还是说我理解有问题?
The text was updated successfully, but these errors were encountered: