package suanfa; import java.util.concurrent.atomic.AtomicInteger; class MyThread extends Thread{ private AtomicInteger flag; public MyThread(AtomicInteger flag){ this.flag = flag; } @Override public void run() { for(int i=0;i<10000;i++){ flag.incrementAndGet(); } } } public class NoLock { public static void main(String[] args) throws Exception { AtomicInteger flag = new AtomicInteger(0); for(int i =0;i<10;i++){ MyThread t1 = new MyThread(flag); t1.start(); } Thread.sleep(5000); System.out.println(flag.get()); } }
无锁类的使用---AtomicInteger
最新推荐文章于 2020-03-30 22:23:57 发布