Skip to content

Commit fd99878

Browse files
committed
add code
1 parent f11c571 commit fd99878

File tree

6 files changed

+154
-103
lines changed

6 files changed

+154
-103
lines changed

.idea/compiler.xml

Lines changed: 9 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/misc.xml

Lines changed: 8 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/workspace.xml

Lines changed: 96 additions & 90 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Java-Interview-Advanced.iml

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<module type="JAVA_MODULE" version="4">
3-
<component name="NewModuleRootManager" inherit-compiler-output="true">
4-
<exclude-output />
2+
<module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4">
3+
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_8">
4+
<output url="file://$MODULE_DIR$/target/classes" />
5+
<output-test url="file://$MODULE_DIR$/target/test-classes" />
56
<content url="file://$MODULE_DIR$">
6-
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
7+
<sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
8+
<sourceFolder url="file://$MODULE_DIR$/src/main/resuorces" isTestSource="false" />
9+
<excludeFolder url="file://$MODULE_DIR$/target" />
710
</content>
811
<orderEntry type="inheritedJdk" />
912
<orderEntry type="sourceFolder" forTests="false" />
1013
</component>
11-
</module>
12-
14+
</module>

pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,5 @@
77
<artifactId>getoffer</artifactId>
88
<version>1.0</version>
99

10+
<properties/>
1011
</project>
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package com.atguigu.interview.juc;
2+
3+
import java.util.concurrent.TimeUnit;
4+
5+
class MyData{
6+
// 可见性验证,可注释后体验效果
7+
volatile int number = 0;
8+
public void add(){
9+
this.number = 10;
10+
}
11+
}
12+
public class VolatileDemo {
13+
public static void main(String[] args) {
14+
MyData myData = new MyData();
15+
new Thread(()->{
16+
System.out.println(Thread.currentThread().getName());
17+
try {
18+
TimeUnit.SECONDS.sleep(3);
19+
} catch(Exception e) {
20+
e.printStackTrace();
21+
}
22+
myData.add();
23+
System.out.println(Thread.currentThread().getName()+" updated number");
24+
},"thread0").start();
25+
26+
while(myData.number == 0){
27+
// main 循环等待
28+
}
29+
System.out.println(Thread.currentThread().getName()+" task is over");
30+
}
31+
32+
}

0 commit comments

Comments
 (0)