From 6012e1a720bf77c2e979925ab161179aa82065df Mon Sep 17 00:00:00 2001 From: 6454d376168b7e02f64e7781 <6454d376168b7e02f64e7781@devide> Date: Fri, 5 May 2023 10:00:20 +0000 Subject: [PATCH] Auto commit --- ThreadLocalTest.java | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 ThreadLocalTest.java diff --git a/ThreadLocalTest.java b/ThreadLocalTest.java new file mode 100644 index 0000000..beff3bd --- /dev/null +++ b/ThreadLocalTest.java @@ -0,0 +1,37 @@ +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());*/ + + } +} -- GitLab