GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — sfsf · owen2016/PassJava-Learning@9fd93c4

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • code/01.Threads/src/com/jackson0714/passjava/threads
    • volatileVisibility.java
  • docs
    • 10.并发编程实战
      • 01.思维导图总结.md
    • 99.tools
      • 02.使用docsify写开源文档.md
    • _coverpage.md
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎code/01.Threads/src/com/jackson0714/passjava/threads/volatileVisibility.java‎

Copy file name to clipboard
+69Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
package com.jackson0714.passjava.threads;
2+
import java.util.concurrent.TimeUnit;
3+
/**
4+
* Volatile Java虚拟机提供的轻量级同步机制
5+
*
6+
* 可见性(及时通知)
7+
* 不保证原子性
8+
* 禁止指令重排
9+
* @author: 悟空聊架构
10+
* @create: 2020-08-12 22:37
11+
*/
12+
13+
14+
class ShareData {
15+
//volatile 修饰的关键字,是为了增加多个线程之间的可见性,只要有一个线程修改了内存中的值,其它线程也能马上感知
16+
volatile int number = 0;
17+
18+
public void setNumberTo100() {
19+
this.number = 100;
20+
}
21+
}
22+
23+
/**
24+
* 验证volatile的可见性
25+
* 1. 假设int number = 0, number变量之前没有添加volatile关键字修饰,没有可见性
26+
* 2. 添加了volatile,可以解决可见性问题
27+
*/
28+
public class volatileVisibility {
29+
public static void main(String[] args) {
30+
// 资源类
31+
ShareData shareData = new ShareData();
32+
33+
// 子线程 实现了Runnable接口的,lambda表达式
34+
new Thread(() -> {
35+
36+
System.out.println(Thread.currentThread().getName() + "\t come in");
37+
38+
// 线程睡眠3秒,假设在进行运算
39+
try {
40+
TimeUnit.SECONDS.sleep(3);
41+
} catch (InterruptedException e) {
42+
e.printStackTrace();
43+
}
44+
// 修改number的值
45+
shareData.setNumberTo100();
46+
47+
// 输出修改后的值
48+
System.out.println(Thread.currentThread().getName() + "\t update number value:" + shareData.number);
49+
50+
}, "子线程").start();
51+
52+
while(shareData.number == 0) {
53+
// main线程就一直在这里等待循环,直到number的值不等于零
54+
}
55+
56+
// 按道理这个值是不可能打印出来的,因为主线程运行的时候,number的值为0,所以一直在循环
57+
// 如果能输出这句话,说明子线程在睡眠3秒后,更新的number的值,重新写入到主内存,并被main线程感知到了
58+
System.out.println(Thread.currentThread().getName() + "\t 主线程知道了 number 不等于 0");
59+
60+
/**
61+
* 最后输出结果:
62+
* 子线程 come in
63+
* 子线程 update number value:100
64+
* 最后线程没有停止,并行没有输出 mission is over 这句话,说明没有用volatile修饰的变量,是没有可见性
65+
*/
66+
}
67+
}
68+
69+
Collapse file

‎docs/10.并发编程实战/01.思维导图总结.md‎

Copy file name to clipboardExpand all lines: docs/10.并发编程实战/01.思维导图总结.md
-11Lines changed: 0 additions & 11 deletions
This file was deleted.
Collapse file

‎docs/99.tools/02.使用docsify写开源文档.md‎

Copy file name to clipboardExpand all lines: docs/99.tools/02.使用docsify写开源文档.md
+2-2Lines changed: 2 additions & 2 deletions
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# 使用docsify 写开源文档
22

3-
文档演示地址:http://tech.jayh.club/
3+
文档演示地址:http://www.jayh.club/
44

55
> docsify 是一个动态生成文档网站的工具。不同于 GitBook、Hexo 的地方是它不会生成将 `.md` 转成 `.html` 文件,所有转换工作都是在运行时进行。
66
@@ -302,7 +302,7 @@ server {
302302
sudo service nginx restart
303303
```
304304

305-
​
305+
306306

307307

308308
# 公众号
Collapse file

‎docs/_coverpage.md‎

Copy file name to clipboard
+6-5Lines changed: 6 additions & 5 deletions
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
![logo](images/logo.png)
22

3-
# Java面试学习平台
3+
# Java面试题管理系统
44

5-
- PassJava是开源的Java面试学习平台
6-
- 零碎时间利用小程序查看常见面试题,夯实Java基础。
7-
- PassJava 项目可以教会你如何搭建SpringBoot项目,Spring Cloud项目。
8-
- 采用流行的技术,如 SpringBoot、MyBatis、Redis、 MySql、 MongoDB、 RabbitMQ、Elasticsearch,采用Docker容器化部署。
5+
- PassJava是开源的面试题管理系统
6+
- `后端`采用SpringBoot+SpringCloud搭建
7+
- `B端`采用Vue-Admin,`C端`采用微信小程序
8+
- 零碎时间利用小程序查看常见面试题,夯实Java基础
9+
- 采用流行的技术,如 SpringBoot、MyBatis、Redis、 MySql、 MongoDB、 RabbitMQ、Elasticsearch,采用Docker容器化部署
910

1011
[GitHub](https://github.com/jackson0714/PassJava-Learning)
1112
[Get Started](README.md)

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.