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 runnable = new Runnable() { @Override public void run() { System.out.println(transmittableThreadLocal.get()); transmittableThreadLocal.set("aaaa"); System.out.println(transmittableThreadLocal.get()); transmittableThreadLocal.set("bbb"); System.out.println(transmittableThreadLocal.get()); try { Thread.sleep(7000); } catch (InterruptedException e) { } System.out.println("Thread 1 执行完毕"); } }; ExecutorService executorService = Executors.newFixedThreadPool(2); TtlRunnable ttlRunnable = TtlRunnable.get(runnable); executorService.execute(ttlRunnable); Runnable runnable1 = new Runnable() { @Override public void run() { System.out.println(transmittableThreadLocal.get()); transmittableThreadLocal.set("111"); System.out.println(transmittableThreadLocal.get()); transmittableThreadLocal.set("222"); System.out.println(transmittableThreadLocal.get()); System.out.println("Thread 2 执行完毕"); } }; TtlRunnable ttlRunnable1 = TtlRunnable.get(runnable1); executorService.submit(ttlRunnable1);
start restore TransmittableThreadLocal$1@4449983f {TransmittableThreadLocal@5754de5a=null} for holder.get() size 1 remove 222 end restore TransmittableThreadLocal$1@4449983f {} holder.get() size 0 end restore TransmittableThreadLocal$1@4449983f {} holder.get() size 0 setTtlValuesTo restore TransmittableThreadLocal$1@4449983f {} holder.get() size 0 restore 结束执行 restore 结束执行 TransmittableThreadLocal$1@4449983f {} holder.get() size 0 Thread 1 执行完毕 run 执行完毕 run 执行完毕 TransmittableThreadLocal$1@4449983f {TransmittableThreadLocal@5754de5a=null} holder.get() size 1 # 这里ttlrunable A sleep完了之后开始restore # 但是TransmittableThreadLocal.holder突然又有值了 # 这里的值啥时候又塞进去了 restore 开始执行 restore 开始执行 TransmittableThreadLocal$1@4449983f {TransmittableThreadLocal@5754de5a=null} holder.get() size 1 restore backupMap 0 doExecuteCallback bbb start restore TransmittableThreadLocal$1@4449983f {TransmittableThreadLocal@5754de5a=null} for holder.get() size 1 remove bbb end restore TransmittableThreadLocal$1@4449983f {} holder.get() size 0 end restore TransmittableThreadLocal$1@4449983f {} holder.get() size 0 setTtlValuesTo restore TransmittableThreadLocal$1@4449983f {} holder.get() size 0 restore 结束执行 restore 结束执行 TransmittableThreadLocal$1@4449983f {} holder.get() size 0
The text was updated successfully, but these errors were encountered:
TtlRunnable A和B共同使用一个TransmittableThreadLocal TtlRunnable A run执行最后一行sleep TtlRunnable B run执行完毕 -> 释放TransmittableThreadLocal holder,holder中的map size == 0 TtlRunnable A开始进入restore,但是进入方法之前,holder中的map值被恢复了,holder还是有值 怎么做到的?
你的信息说明 还不清楚。比如
『TtlRunnable A开始进入restore,但是进入方法之前,holder中的map值被恢复了』
不清楚你说的是,恢复 成什么了?你期望的恢复 成什么?
holder
InheritableThreadLocal
ThreadLocal
TransmittableThreadLocal
Sorry, something went wrong.
感谢提醒, 想起来了 holder本身是一个Threadlocal所以线程b释放的是自己的threadlocal 所以有值
oldratlee
No branches or pull requests
源码学习提问
怎么做到的?
The text was updated successfully, but these errors were encountered: