Finally they do not execute if you kill the VM (or if the VM dies in another way). System.exit () is a pretty crude method of killing a program, while finally it is a high-level OOP concept. System.exit () takes really fast, doing as little cleanup as possible.
If you went into the task manager and killed the process or released kill -9 in the process, did you expect it to finally execute? It is vaguely (very vaguely) the same.
There are a few things worth noting. In particular, I lied a bit in the first part of the post. This is misleading to liken System.exit() to really kill the program instantly. In particular, stop hooks are triggered and, if configured , finalizers can be triggered. Note, however, that the docs quite strongly indicate the use of runFinalizersOnExit .
Corbin Feb 15 2018-12-23T00: 00Z
source share