Skip to content

Commit 0097e55

Browse files
committed
Update 2020最新Java并发进阶常见面试题总结.md
1 parent 44541c3 commit 0097e55

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

docs/java/multi-thread/2020最新Java并发进阶常见面试题总结.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,8 @@ synchronized void method() {
9393
**2.修饰静态方法:** 也就是给当前类加锁,会作用于类的所有对象实例 ,进入同步代码前要获得 **当前 class 的锁**。因为静态成员不属于任何一个实例对象,是类成员( _static 表明这是该类的一个静态资源,不管 new 了多少个对象,只有一份_)。所以,如果一个线程 A 调用一个实例对象的非静态 `synchronized` 方法,而线程 B 需要调用这个实例对象所属类的静态 `synchronized` 方法,是允许的,不会发生互斥现象,**因为访问静态 `synchronized` 方法占用的锁是当前类的锁,而访问非静态 `synchronized` 方法占用的锁是当前实例对象锁**
9494

9595
```java
96-
synchronized void staic method() {
97-
//业务代码
96+
synchronized static void method() {
97+
//业务代码
9898
}
9999
```
100100

0 commit comments

Comments
 (0)