高并发: High Concurrency
CPU 多级缓存: 数据 存取 通过高速缓存 cache。一级缓存 二级缓存 三级缓存
时间局部性 空间局部性
缓存一致性 MESI (修改 独享 共享 无效)
乱序执行优化
JAVA虚拟机-内存模型 JMM
堆: 用户对象信息存储
栈: 对象引用、基本类型变量存储,堆区对象的私有拷贝
import com.imooc.concurrency.annoations.NodThreadSafe;import java.util.concurrent.CountDownLatch;import java.util.concurrent.ExecutorService;import java.util.concurrent.Executors;import java.util.concurrent.Semaphore;@NodThreadSafepublic class ConcurrentyTest { // 请求总数 public static int countTotle = 5000; // 并发执行线程数 public static int threadTotle = 200; public static int sum = 0; public static void main(String[] args)throws Exception { ExecutorService executorService = Executors.newCachedThreadPool(); //线程池 final Semaphore semaphore = new Semaphore(threadTotle); //信号量 final CountDownLatch countDownLatch = new CountDownLatch(countTotle); // 计数器 for (int i=0;i{ try { semaphore.acquire(); // 是否允许被执行 add(); semaphore.release(); } catch (Exception e) { e.printStackTrace(); } countDownLatch.countDown();//计数器 -1 }); } countDownLatch.await(); executorService.shutdown(); System.out.println(sum); } private static void add() { sum++; }}