此类特性是什么?

简单问题一个:
1.这段代码什么意思?
2.有什么特性?
3.这样的代码真正的意义是什么?

public class Test {
    private static int index = 0;
    private static ThreadLocal t = new ThreadLocal() {
        protected synchronized Object initialValue() {
            return new Integer(index++); }
    };
    public static int get() {
        return ((Integer) (t.get())).intValue();
    }
} 

 

 

ThreadLocal变量在同一个线程内是共享的,
相同线程访问Test时,t是相同的,不同线程的t不同
[code="java"] public static void main(String[] args) {
for (int i = 0; i < 100; i++) {
new Thread(){
@Override
public void run() {
System.out.println(Test.get());
System.out.println(Test.get());
};
}.start();
}
}[/code]

比如如上代码,同一个线程内打印的值是相同的
一个新的线程会重新生一个t,所以值增加了
打印的范围是0-99
顺序可能不同