search

Home  >  Q&A  >  body text

jvm - How to execute the specified command when java exits abnormally

Just before the java process exits abnormally, how to execute the specified command to retain the state of the system at that time? I saw a blog on the Internet that said that commands can be executed, but there was no specific explanation. .

PHPzPHPz2750 days ago622

reply all(1)I'll reply

  • 大家讲道理

    大家讲道理2017-05-17 10:02:01

    Is the abnormal exit you are talking about a jvm crash? Or just throw an Error like OOM?
    If it is the former, then no measures can guarantee that you will record the status of the system. It is very likely that like TerminateProcess and kill -9, the process will disappear without leaving a trace. TerminateProcesskill -9一样,进程会不留痕迹地消失。
    如果是后者的话,addShutdownHookIf it’s the latter, addShutdownHook should be able to do it.

    reply
    0
  • Cancelreply