There is no (standard) way to find out when your application will be killed by the task manager with Java.
The usual approach is to have a second application that runs the main application as a child process (use ProcessBuilder ). The wrapper will notice when the baby dies. For all common reasons for termination, set the exit code through System.exit() in the main application. Check the exit code in your wrapper. If this is not the one you explicitly asked, then someone killed the application or it crashed due to a VM error.
To distinguish between the two, check the output of the child application and find the VM crash dumps in the current directory (no matter what your application might be, it is usually the directory in which your application was installed).
source share