package com.shizhuang.duapp.push; import com.google.common.util.concurrent.ThreadFactoryBuilder; import com.shizhuang.duapp.channel.dto.priority.PrioritySeqDTO; import com.shizhuang.duapp.channel.pool.PriorityThreadPoolExecutor; import java.util.concurrent.*; /** * Created by wu.guofeng on 2023/5/5 下午4:26 */ public class ThreadLocalTest { public static InheritableThreadLocal threadLocal = new InheritableThreadLocal(); static ExecutorService executorService = Executors.newFixedThreadPool(1); public static void main(String[] args){ threadLocal.set("china"); System.out.println("thread: " + Thread.currentThread().getName() + " country: " + threadLocal.get()); executorService.submit(()->{ System.out.println("thread1: " + Thread.currentThread().getName() + " country: " + threadLocal.get()); threadLocal.set("china2"); }); threadLocal.set("china3"); executorService.submit(()->{ System.out.println("thread2: " + Thread.currentThread().getName() + " country: " + threadLocal.get()); }); /*ThreadFactory threadFactory = new ThreadFactoryBuilder().setNameFormat("testThreadLocal").build(); PriorityThreadPoolExecutor priorityThreadPoolExecutor = new PriorityThreadPoolExecutor(1, 1, 0L, TimeUnit.MICROSECONDS, threadFactory, new ThreadPoolExecutor.CallerRunsPolicy()); priorityThreadPoolExecutor.submit(()->{ System.out.println("thread: " + Thread.currentThread().getName()); }, PrioritySeqDTO.init());*/ } }