Skip to content

Commit a1ce9d6

Browse files
committed
Snailclimb#511 fix typo error
1 parent 888dfc8 commit a1ce9d6

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

docs/java/Multithread/JavaConcurrencyAdvancedCommonInterviewQuestions.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ uniqueInstance 采用 volatile 关键字修饰也是很有必要的, uniqueIns
9595
2. 初始化 uniqueInstance
9696
3. 将 uniqueInstance 指向分配的内存地址
9797

98-
但是由于 JVM 具有指令重排的特性,执行顺序有可能变成 1->3->2。指令重排在单线程环境下不会出先问题,但是在多线程环境下会导致一个线程获得还没有初始化的实例。例如,线程 T1 执行了 1 和 3,此时 T2 调用 getUniqueInstance() 后发现 uniqueInstance 不为空,因此返回 uniqueInstance,但此时 uniqueInstance 还未被初始化。
98+
但是由于 JVM 具有指令重排的特性,执行顺序有可能变成 1->3->2。指令重排在单线程环境下不会出现问题,但是在多线程环境下会导致一个线程获得还没有初始化的实例。例如,线程 T1 执行了 1 和 3,此时 T2 调用 getUniqueInstance() 后发现 uniqueInstance 不为空,因此返回 uniqueInstance,但此时 uniqueInstance 还未被初始化。
9999

100100
使用 volatile 可以禁止 JVM 的指令重排,保证在多线程环境下也能正常运行。
101101

0 commit comments

Comments
 (0)