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

后端 未结 7 1575
情书的邮戳
情书的邮戳 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 02:58

    There is absolutely nothing wrong with calling System.exit from any thread you wish. Letting it exit "normally" does not work in practice, because you'll find that the app will be hanging around while the GC collects stuff, before the app quits. I've written tons of gui Swing apps, and there is absolutely nothing wrong with calling it. It's not "rude" either. It's the Java way.

提交回复
热议问题