![](/img/trans.png)
[英]How to view multiple stack traces while debugging a multi-threaded java application in Intellij?
[英]How to debug a multi-threaded app in IntelliJ?
我在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");
}
}
}
當我在第12行放置一個斷點(全部掛起)時,已synchronized (this.lock)
, System.out.println
仍然執行(有時幾次)。 這是屏幕截圖:
據我所知,所有線程都應在斷點處停止。
文檔閱讀混亂,但這是相關的塊。 歸結為將屬性設置為在線程上掛起,而不是整個應用程序掛起。 這將導致您擊中每個單獨線程的斷點,而不是任意不確定的線程。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.