Skip to content

分布式追踪系统场景下,如何使用TTL #53

@wyzssw

Description

@wyzssw

子线程无法修改父线程 threadlocal,不知道设计时是否支持该功能

ExecutorService service = Executors.newFixedThreadPool(1);

    ExecutorService executorService = TtlExecutors.getTtlExecutorService(service); 

     final TransmittableThreadLocal<String> parent = new TransmittableThreadLocal<String>();
     parent.set("value-set-in-parent");

     executorService.submit(new Runnable() {

      @Override
      public void run() {
        System.out.println(parent.get());
        parent.set("asf");
      }
    });

     Thread.sleep(1000);
     String value = parent.get(); 
     System.out.println(value);

打印出

value-set-in-parent
value-set-in-parent

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions