The code in Worker.java acquires synchronization objects in different order (once acquires jobs and then this, another time acquires this and then jobs).
Acquiring synchronization objects in different order can cause circular wait (deadlock).
Here is the first order: (1) first acquire 'jobs' and then 'this':
enter public method run() at line 40
acquire synchronization on jobs at line 43
call isStopped() at line 44
acquire synchronization on this at entry to isStopped() because isStopped() is
a synchronized method --- see line 59
Here is the second order: (2) first acquire 'this' and then 'jobs':
enter public method stopWorker() at line 63
acquire synchronization on this at entry to stopWorker() because
stopWorker() is a synchronized method --- see line 63
acquire synchronization on jobs at line 65
one possible bugfix is to makes code always acquire synchronization in only 1 order: first acquire jobs and then this.
public void stopWorker() { <<<<<<<<<<<<<<<< moved synchronized from
here to below as "synchronized(this)"
synchronized(jobs) {
synchronized(this) { <<<<<<<<<<<<<<<<<<<<<<<<<< added this
stopped = true;
jobs.notify();
}
}
}
Reference:
https://hg.openjdk.java.net/jdk/jdk/file/b997e5b9479b/src/jdk.jconsole/share/classes/sun/tools/jconsole/Worker.java#l63
Acquiring synchronization objects in different order can cause circular wait (deadlock).
Here is the first order: (1) first acquire 'jobs' and then 'this':
enter public method run() at line 40
acquire synchronization on jobs at line 43
call isStopped() at line 44
acquire synchronization on this at entry to isStopped() because isStopped() is
a synchronized method --- see line 59
Here is the second order: (2) first acquire 'this' and then 'jobs':
enter public method stopWorker() at line 63
acquire synchronization on this at entry to stopWorker() because
stopWorker() is a synchronized method --- see line 63
acquire synchronization on jobs at line 65
one possible bugfix is to makes code always acquire synchronization in only 1 order: first acquire jobs and then this.
public void stopWorker() { <<<<<<<<<<<<<<<< moved synchronized from
here to below as "synchronized(this)"
synchronized(jobs) {
synchronized(this) { <<<<<<<<<<<<<<<<<<<<<<<<<< added this
stopped = true;
jobs.notify();
}
}
}
Reference:
https://hg.openjdk.java.net/jdk/jdk/file/b997e5b9479b/src/jdk.jconsole/share/classes/sun/tools/jconsole/Worker.java#l63
- duplicates
-
JDK-8236873 Worker has a deadlock bug
-
- Resolved
-