典型的线程安全
Java代码
public class A1 {
public static ThreadLocal tl = new ThreadLocal();
static Integer a=1;
public static void main(String[] args) {
for (int i = 0; i < 3; i++) {
new Thread() {
public void run() {
try {
synchronized (a) {
Thread.sleep(10);
tl.set(Thread.currentThread().getName()+"-----"+a++);
System.out.println(Thread.currentThread().getName()+"-----"+tl.get());
// b.getTl().remove();
}
} catch (Exception e) {
e.printStackTrace();
}
}
}.start();
}
}
}
作者“J2EE技术探讨”
补充:综合编程 , 安全编程 ,