Skip to content

Commit dadddb3

Browse files
author
yangfei
committed
update
1 parent 0be4e02 commit dadddb3

1 file changed

Lines changed: 13 additions & 10 deletions

File tree

‎JavaStudy/src/main/java/com/yf/java/study/thread/yield/SyncThread.java‎

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,18 +28,21 @@ public SyncThread(int value) {
2828
/**
2929
* 对这个类的实例化对象进行检查
3030
*/
31-
private synchronized void doOtherthing() {
32-
NOWVALUE = this.value;
33-
LOGGER.info("当前NOWVALUE的值:" + NOWVALUE);
34-
}
35-
36-
// private void doOtherthing() {
37-
// synchronized (SyncThread.class) {
38-
// NOWVALUE = this.value;
39-
// LOGGER.info("当前NOWVALUE的值:" + NOWVALUE);
40-
// }
31+
// private synchronized void doOtherthing() {
32+
// NOWVALUE = this.value;
33+
// LOGGER.info("当前NOWVALUE的值:" + NOWVALUE);
4134
// }
4235

36+
/**
37+
* 进行SyncThread类的多个实例对象进行同步检查,需要对SyncThread类的class对象进行同步检查
38+
*/
39+
private void doOtherthing() {
40+
synchronized (SyncThread.class) {
41+
NOWVALUE = this.value;
42+
LOGGER.info("当前NOWVALUE的值:" + NOWVALUE);
43+
}
44+
}
45+
4346
@Override
4447
public void run() {
4548
Thread thread = Thread.currentThread();

0 commit comments

Comments
 (0)