Catch when java process has been terminated

后端 未结 4 476
有刺的猬
有刺的猬 2021-01-13 20:50

How can I catch when somebody kills my application (java, but it is not important) by taskmanager or by taskkill console command?

I understand that I cannot catch t

4条回答
  •  星月不相逢
    2021-01-13 21:36

    You can do simply by java application too, by using two apps. This is how it is done in many pure java produciton systems

    1. Your main app will make .lock file in a standard locaiton and lock it exclusively.
    2. Your other program(maybe call it janitor app) will keep do a lock() call on it and keep on waiting.

    3. When the lock call returns you can be sure that your main app is terminated. Now you can determine.

      As far as "Why applicaiton is killed " question, technically you cannot find out(maybe 1 or 2 scenarios , but not all scenarios), AFAIK.

提交回复
热议问题