简体   繁体   中英

How to gracefully shutdown a Java application when of closing the Windows console?

This question has been asked before , but there is still no answer.

The scenario is that a Java command line program is started from a Windows console window. The program is still executed when the "X" close button of the console window is pressed.

The effect is that the programm is terminated without the shutdown hooks beeing executed (they are in place and react properly on Ctrl-C).

This answer to that question suggests that it is possible to do it from C.

Is there a (possibly platform specific) library that allows to react to the closing event and use the SetConsoleCtrlHandler from Java?

也许可以使用JNA在Windows消息上设置挂钩:WM_CLOSE,并检查它是否由应用程序窗口的句柄触发。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM