
本文共 4049 字,大约阅读时间需要 13 分钟。
���������������������������
������������������������������������������������������������������������������������������������������������������������������������������CPU������������������������������������������������������������������������������������������������������CPU���������������������������������������������������������������
���������������������������������CPU������������������������Cache������������������������������������������������������������������������������CPU���������������������������������CPU���������������������������������������������������������������������������������������������������������������������������������������������������������
Java���������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������
������������������������������������
volatile���������������������������������������������������������������������������������������������������������������������������������������volatile������������������������������������������������������������������������������������������������������������������������������������������������������������������������������
���������������volatile���������������������������������������������������������������������������������������������������������
public static volatile int t = 0;public static void main(String[] args) throws InterruptedException { for (int i=0;i<100;i++) { for (int j=0;j<100;j++) { new Thread(new Runnable() { @Override public void run() { t = t + 1; } }).start(); } // ������t������ System.out.println(t); Thread.sleep(1000); t = 0; }}
������������������������������������������������������������������������������������������t���������������������������������������������������������������������������������������������
���������������������������������������������������������������������atomicity���������������������������������������������������������������������������������������������������������������synchronized������������Lock������������Java.util.concurrent������������������������AtomicInteger������
������������������synchronized������Lock���������������������������������������������������������������������������������������AtomicInteger���������������������������������������������������������������������������������������������������������������������������������������
������������������������������AtomicInteger������������������������
public static AtomicInteger t = new AtomicInteger(0);public static void main(String[] args) throws InterruptedException { for (int i=0;i<100;i++) { for (int j=0;j<100;j++) { new Thread(new Runnable() { @Override public void run() { int x = t.incrementAndGet(); System.out.println("t after " + x); } }).start(); } // ������t������ Thread.sleep(2000); System.out.println(t); t = new AtomicInteger(0); }}
���������������������������������������������������2000���������������������t���������������������������������������������������������t���������������t���������������������������������������������
���������������volatile������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������
���������������������������������������������������������������������������������������������������������������������������������������������������������������������������
发表评论
最新留言
关于作者
