Giter Site home page Giter Site logo

Comments (3)

oldratlee avatar oldratlee commented on April 28, 2024 1

这样假如此时 另外一个线程池中的线程 调用了copy()方法

holder.get()ThreadLocal的(holder本身是ThreadLocal),只属于当前线程。
# ThreadLocal#get() 只能 拿到 当前线程 的数据。

即这个数据不会被另一个线程访问使用的,没有并发问题。

更具体 可以再看看一下ThreadLocal的使用与限制。


// 没太理解此处,为何将copied中不存在,holder中存在的 threadlocal remove?

// clear the TTL value only in copied
// avoid extra TTL value in copied, when run task.
if (!copied.containsKey(threadLocal)) {
    iterator.remove();
    threadLocal.superRemove();
}

上面的代码注释 说明了。

如果不这么做这个删除,那么 TTL这些值 就比 copied 里多出来了,
不没有正确 恢复/回放值。

比如 原来的copy过来的值是 a=1,b=2,回放运行的线程原来就有值z=100
不做这个删除,回放运行时,就有值a=1,b=2,z=100,不预期了。

可以自己写段代码运行Debug一下就好了,或者 自己理解一下TTL的执行过程,这个就很容易理解了。


PS

这个Issue也提交错了 仓库,@tianjialin 请 提交到 ❤️
https://github.com/alibaba/transmittable-thread-local/issues

from translations.

tianjialin avatar tianjialin commented on April 28, 2024

仔细有想了想 ThreadLocal 的运行原理,理解了,非常感谢百忙之中回复。

另:
我是单击 TransmittableThreadLocal 仓库下README里 “建议和提问,提交Issue” 进来的,我还以为提问都是在这提问。操作有误,实在抱歉

from translations.

oldratlee avatar oldratlee commented on April 28, 2024

麻烦 提到ttl中,方便大家也看到了解,谢谢

我是单击 TransmittableThreadLocal 仓库下README里 “建议和提问,提交Issue” 进来的,我还以为提问都是在这提问。

README 有误,给个pr fix一下? 💕

from translations.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.