首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > 编程 >

典型的线程保险

2012-10-10 
典型的线程安全public class A1 {public static ThreadLocal tl new ThreadLocal() static Integer a1

典型的线程安全

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();}}}

?

热点排行