为什么intellij想法不会立即终止调试过程?

时间:2016-04-20 13:31:30

标签: debugging intellij-idea

我正在使用 idea 2016.1.1 ,并想知道为什么当我点击停止按钮时,想法不会立即终止调试过程。

E.g。使用这段代码重现它

public class Main {

  public static void main(String[] args) {
    int i = 0;
    while (true) {
      i++;
      System.out.print("I'm still alive: ");
      System.out.println(i);
    }
  }
}

在循环开始之前设置断点。

enter image description here

启动调试会话,等到它休息并按红色停止按钮(CTRL-F2)。

enter image description here

我希望这个过程立即停止并且它不会打印任何内容,但会打印出来:

"C:\Program Files\Java\jdk1.6.0_38\bin\java" ....
Connected to the target VM, address: '127.0.0.1:54394', transport: 'socket'
Disconnected from the target VM, address: '127.0.0.1:54394', transport: 'socket'
I'm still alive: 1
I'm still alive: 2
I'm still alive: 3
I'm still alive: 4
...
I'm still alive: 319
I'm still alive: 320
I'm still alive: 321
I'm still alive: 
Process finished with exit code -1

为什么流程没有立即停止?

是否有其他方法可以立即停止?

修改

刚刚尝试了 idea 14.1.5 。该过程会按预期立即停止。 2016年似乎引入了一个错误。

3 个答案:

答案 0 :(得分:4)

到目前为止我的调查......

当IDEA启动java进程时,它使用主包装器。此包装器启动一个守护程序线程,该线程侦听ServerSocket命令。

IDEA向该服务器套接字发送STOP信号。当服务器线程收到STOP信号时,它使用System.exit(1)存在jvm。

似乎IDEA从调试中恢复JVM,然后发送STOP信号。因此,在收到STOP信号之前,该过程将继续。

我在https://youtrack.jetbrains.com/issue/IDEA-155007

打开了一个错误

答案 1 :(得分:3)

错误IDEA-155007已在 2016.3(163.7743.44)中修复。我刚刚验证了它。

答案 2 :(得分:0)

在调试会话期间按 Stop 时,
IntelliJ Idea 的默认行为不立即终止进程!

但是如果您需要更改此行为以立即终止调试过程
我认为,应该是默认行为:)

您可以通过设置激活它:
Settings > Build, Execution, Development > Debugger >

enter image description here