File tree Expand file tree Collapse file tree 2 files changed +39
-0
lines changed
src/main/java/com/cpucode/java/volati Expand file tree Collapse file tree 2 files changed +39
-0
lines changed Original file line number Diff line number Diff line change 114114
115115-------------------------
116116
117+ ## [ volatile] ( src/main/java/com/cpucode/java/volati )
118+
119+ - [x] [ volatile的可见性] ( src/main/java/com/cpucode/java/volati/VolatileDemo.java )
120+
121+ - [ 返回文件目录] ( #文件目录 )
122+
123+ -------------------------
117124
118125- [x] [ Thread1__ 创建新线程] ( src/main/java/com/cpucode/java/thread/Thread1.java )
119126- [x] [ Thread2__ 自定义线程] ( src/main/java/com/cpucode/java/thread/Thread2.java )
Original file line number Diff line number Diff line change 1+ package com .cpucode .java .volati ;
2+
3+ import org .omg .Messaging .SYNC_WITH_TRANSPORT ;
4+
5+ /**
6+ * @author : cpucode
7+ * @date : 2021/7/28
8+ * @time : 10:26
9+ * @github : https://github.com/CPU-Code
10+ * @csdn : https://blog.csdn.net/qq_44226094
11+ */
12+ public class VolatileDemo {
13+ //public volatile static boolean stop = false;
14+ public static boolean stop = false ;
15+
16+ public static void main (String [] args ) throws InterruptedException {
17+ Thread thread = new Thread (() -> {
18+ int i = 0 ;
19+
20+ while (!stop ){
21+ i ++;
22+ }
23+ });
24+
25+ thread .start ();
26+
27+ System .out .println ("begin start thread" );
28+
29+ Thread .sleep (1000 );
30+ stop = true ;
31+ }
32+ }
You can’t perform that action at this time.
0 commit comments