From which thread should System.exit() be called in a Swing-app?

后端 未结 7 1527
情书的邮戳
情书的邮戳 2021-01-18 02:04

In a Swing-app is it okay to invoke System.exit() from any thread? (e.g. on the EDT?)

7条回答
  •  攒了一身酷
    2021-01-18 03:03

    You should not be calling System.exit() if you can help it.

    The best way to exit a java process is to let all threads exit normally. This will terminate the VM.

    In your main JFrame, you should setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE).

    Then you can call frame.dispose() to close the JFrame and exit the EDT.

提交回复
热议问题