m0s*_*it0 53 java debugging multithreading intellij-idea
我在IntelliJ IDEA 14.0.2中有多个线程和断点的奇怪问题.断点在停止之前执行之后的代码.
import java.util.concurrent.atomic.AtomicInteger;
public class Main {
private static final int NUM_CLIENTS = 1000;
static class TestRunnable implements Runnable {
AtomicInteger lock;
@Override
public void run() {
synchronized (this.lock) {
int curCounter = this.lock.addAndGet(1);
System.out.println("Thread: " + Thread.currentThread().getName() + "; Count: " + curCounter);
if (curCounter >= NUM_CLIENTS) {
lock.notifyAll();
}
}
}
}
public static void main(final String args[]) {
final AtomicInteger lock = new AtomicInteger(0);
for (int i = 0; i < NUM_CLIENTS; i++) {
TestRunnable tr1 = new TestRunnable();
tr1.lock = lock;
new Thread(tr1).start();
}
synchronized (lock) {
try {
lock.wait();
} catch (InterruptedException e) {
e.printStackTrace();
}
System.out.println("Main woken up");
}
}
}
Run Code Online (Sandbox Code Playgroud)
当我在第12行放置一个断点(Suspend All)时synchronized (this.lock),System.out.println仍然执行(有时几次).这是一个截图:

据我所知,所有线程都应该在断点处停止.
Mak*_*oto 123
文档令人困惑,但这是相关的块. 它提炼的内容是将属性设置为挂起线程,而不是整个应用程序.这将导致您在每个单独的线程上而不是任意的,不确定的线程中达到断点.

| 归档时间: |
|
| 查看次数: |
37770 次 |
| 最近记录: |