ThreadLocal是依赖于线程的!
import java.util.*;import java.util.concurrent.*;import java.util.concurrent.locks.*;import java.io.*;public class Test1 implements Runnable{static ThreadLocal<Integer> t=new ThreadLocal<Integer>(){@Overrideprotected synchronized Integer initialValue(){return new Integer(0);}};static int count=0;final int id=count++;public Test1(){t.set((Integer)id);//这个执行了嘛?System.out.println("Constructor:"+id);}public void run(){t.set(t.get()+1);System.out.println(t.get());}public static void main(String[] args){ExecutorService exec=Executors.newCachedThreadPool();for (int i=0;i<5;i++)exec.execute(new Test1());exec.shutdownNow();}}