Giter Site home page Giter Site logo

请问下,在spring boot 场景下,filter 中进入时set ,但是业务中异步线程还未执行完,filter 请求已经finally remove了,这时获取到的值为null, 这种情况如何保证正确性 about transmittable-thread-local HOT 3 CLOSED

freshgeek avatar freshgeek commented on June 9, 2024
请问下,在spring boot 场景下,filter 中进入时set ,但是业务中异步线程还未执行完,filter 请求已经finally remove了,这时获取到的值为null, 这种情况如何保证正确性

from transmittable-thread-local.

Comments (3)

freshgeek avatar freshgeek commented on June 9, 2024 1

TransmittableThreadLocal数据丢失问题
https://juejin.cn/post/7311500203432575026

from transmittable-thread-local.

oldratlee avatar oldratlee commented on June 9, 2024

对于TTL本身逻辑/功能,
主线程的修改(filter请求的remove)不会影响 给子任务传递了的值。

一般是因为ThreadLocal的值使用了共享的集合(如Map),所以修改子任务可见。可以看看: @freshgeek

这个TTL使用方式/问题的解决方法,可以看看:

更多可以看看:

  • #123
  • 或是 源码

from transmittable-thread-local.

oldratlee avatar oldratlee commented on June 9, 2024

TransmittableThreadLocal数据丢失问题 https://juejin.cn/post/7311500203432575026

executor.setTaskDecorator(runnable -> TtlRunnable.get(runnable, true));

// 推荐改成

executor.setTaskDecorator(TtlRunnable::get);

// 以避免不能在线程池中运行(可能)多次重复运行的任务

from transmittable-thread-local.

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.