How to shutdown java application correctly from C# one
-
18-06-2021 - |
Domanda
I have java application which shutdowns correctly when i use CTRL-C
, java application saves all data before shutdown. Now i trying to shutdown this java application from my C# console application using Process.Close()
, but application dont't save any data when i use this, i also tried Process.CloseMainWindow()
but using this nothing is happening, and also Process.Kill()
but using this process just killed, without any savining.
How can i raise shutdown hook on java application from C# console application?
Soluzione
A shutdown hook cannot be raised by another app.
The shutdown hook runs when:
- A program exists normally. For example,
System.exit()
is called, or the last non-daemon thread exits. - the Virtual Machine is terminated. e.g. CTRL-C. This corresponds to kill -SIGTERM pid or kill -15 pid on Unix systems.
The shutdown hook will not run when:
- the Virtual Machine aborts
- A SIGKILL signal is sent to the Virtual Machine process on Unix systems. e.g. kill -SIGKILL pid or kill -9 pid
- A TerminateProcess call is sent to the process on Windows systems.
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow