如何从子线程中的ThreadLocal继续对象? [英] How to continue object from ThreadLocal in child thread?

查看:118
本文介绍了如何从子线程中的ThreadLocal继续对象?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在ThreadLocal中传递了一个对象。
现在我的当前线程将创建新的Child线程。
我想要来自ThreadLocal的对象也应继续使用子线程。

I have passed one object in ThreadLocal. Now my current thread going to create new Child thread. I want object from ThreadLocal should continue with child thread also.

有没有办法这样做....?

Is there any way to do so....?

提前感谢....

推荐答案

您可以从 ThreadLocal 通过 get()方法并将此引用传递给您的子线程。

You may retrieve the object itself from your ThreadLocal via the get() method and pass this reference to you child thread.

如果你想与你的子线程分享它,请参阅其他答案。

If instead you want to share it with your child threads, see other answers.

这篇关于如何从子线程中的ThreadLocal继续对象?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆