Skip to content

Commit 2226a87

Browse files
committed
synchronized关键字代码示例 语法错误修复
1 parent 56f7fb3 commit 2226a87

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

docs/b-3Java多线程.md

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

306306
```java
307-
synchronized void staic method() {
307+
synchronized staic void method() {
308308
//业务代码
309309
}
310310
```

0 commit comments

Comments
 (0)