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

TransmittableThreadLocal 是否线程安全 #175

Closed
xingguang2013 opened this issue May 19, 2020 · 2 comments
Closed

TransmittableThreadLocal 是否线程安全 #175

xingguang2013 opened this issue May 19, 2020 · 2 comments
Assignees
Labels
🔰 first nice issue 👍 ❓question Further information is requested

Comments

@xingguang2013
Copy link

如题, TransmittableThreadLocal 类是否是线程安全的?查阅资料没有找到相关说明

@oldratlee
Copy link
Member

oldratlee commented May 19, 2020

简单的回答

TransmittableThreadLocal是线程安全的。 @xingguang2013

关于库的线程安全性声明

  • 对于涉及多线程的库来说(如ThreadLocal),缺省要是线程安全,否则就是 BUG
  • 即,如不是线程安全,则要显式声明出来。

更完整的回答

库的线程安全,是以正确使用为前提,还要加上使用者相关知识的了解,如:

  • ThreadLocal的了解(这是个具体主题 学习)
  • 对线程安全/并发(这是个通用主题 学习)

比如 使用ThreadLocal时,取出ThreadLocal的值(对象引用)并传到其它线程,就要使用者注意额外的线程安全问题了。


更多了解可以看一下TTL的资料/文档: @xingguang2013 ❤️

@oldratlee oldratlee self-assigned this May 19, 2020
@oldratlee oldratlee added the ❓question Further information is requested label May 19, 2020
@xingguang2013
Copy link
Author

感谢感谢

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🔰 first nice issue 👍 ❓question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants