
并发编程
文章平均质量分 93
Gordon_Java
平平无奇,一枚小程序员。
展开
-
03 java内存模型
一、从一个程序开始说起 static boolean run = true; public static void main(String[] args) throws InterruptedException { Thread t = new Thread(()->{ while(run){ // .... } }); t.start(); sleep(1); run = false; // 线程t不会如预想的停下来 } 执行上面的代码,会发现程序根本停不下来。这是为什么呢原创 2022-04-09 10:51:00 · 72 阅读 · 0 评论 -
02 锁的原理
一、先来看下面的程序 两个线程对初始值为 0 的静态变量一个做自增,一个做自减,各做 5000 次,结果是 0 吗? package com.gaoxin.courrent; public class Demo01 { public static int count = 0 ; public static void main(String[] args) throws InterruptedException { Thread t1 = new Thread(()原创 2022-04-08 22:31:05 · 367 阅读 · 0 评论