File tree Expand file tree Collapse file tree 2 files changed +5
-5
lines changed Expand file tree Collapse file tree 2 files changed +5
-5
lines changed Original file line number Diff line number Diff line change 168
168
169
169
学习笔记不是从网上到处拼凑而来,除了少部分引用书上和技术文档的原文,其余都是笔者的原创。在您引用本仓库内容或者对内容进行修改演绎时,请遵循文末的开源协议,谢谢。
170
170
171
- #### BookList
172
-
173
- 本仓库参考的书目:[ BOOKLIST] ( https://github.com/CyC2018/Interview-Notebook/blob/master/BOOKLIST.md ) 。
174
-
175
171
#### How To Contribute
176
172
177
173
笔记内容是笔者一个字一个字打上去的,难免会有一些笔误,如果发现笔误可直接对相应文档进行编辑修改。
180
176
181
177
欢迎在 Issue 中提交对本仓库的改进建议~
182
178
179
+ #### BookList
180
+
181
+ 本仓库参考的书目:[ BOOKLIST] ( https://github.com/CyC2018/Interview-Notebook/blob/master/BOOKLIST.md ) 。
182
+
183
183
#### Typesetting
184
184
185
185
笔记内容按照 [ 中文文案排版指北] ( https://mazhuang.org/wiki/chinese-copywriting-guidelines/ ) 进行排版,以保证内容的可读性。
Original file line number Diff line number Diff line change @@ -149,7 +149,7 @@ uniqueInstance 采用 volatile 关键字修饰也是很有必要的, `uniqueIn
149
149
2 . 初始化 uniqueInstance
150
150
3 . 将 uniqueInstance 指向分配的内存地址
151
151
152
- 但是由于 JVM 具有指令重排的特性,执行顺序有可能变成 1>3>2。指令重排在单线程环境下不会出先问题 ,但是在多线程环境下会导致一个线程获得还没有初始化的实例。例如,线程 T<sub >1</sub > 执行了 1 和 3,此时 T<sub >2</sub > 调用 getUniqueInstance() 后发现 uniqueInstance 不为空,因此返回 uniqueInstance,但此时 uniqueInstance 还未被初始化。
152
+ 但是由于 JVM 具有指令重排的特性,执行顺序有可能变成 1>3>2。指令重排在单线程环境下不会出现问题 ,但是在多线程环境下会导致一个线程获得还没有初始化的实例。例如,线程 T<sub >1</sub > 执行了 1 和 3,此时 T<sub >2</sub > 调用 getUniqueInstance() 后发现 uniqueInstance 不为空,因此返回 uniqueInstance,但此时 uniqueInstance 还未被初始化。
153
153
154
154
使用 volatile 可以禁止 JVM 的指令重排,保证在多线程环境下也能正常运行。
155
155
You can’t perform that action at this time.
0 commit comments