子线程中获取父线程的数据
static InheritableThreadLocal<String> local = new InheritableThreadLocal<>(); public static void main(String[] args) { local.set("123"); System.out.println(Thread.currentThread().getName() + " ======= " + local.get()); try { Thread thread = new Thread(()->{ System.out.println(Thread.currentThread().getName() + " ======= " + local.get()); local.set("456"); System.out.println(Thread.currentThread().getName() + " ======= " + local.get()); },"child"); thread.start(); thread.join(); } catch (InterruptedException e) { e.printStackTrace(); } System.out.println(Thread.currentThread().getName() + " ======= " + local.get()); }
标签:Thread,currentThread,池下,System,线程,失效,local,out From: https://www.cnblogs.com/yexuba/p/17292605.html