Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [aspectj-users] Capturing shutdown

Eric Bodden wrote:
Hmmm... I am a bit confused. So is it generally possible to run
various applications on the same VM instance, so that one application
can quit, e.g. using System.exit(..) but still no shutdown hooks are
run since another application is still running on the same VM?

System.exit(..) causes orderly VM termination (w/ hooks etc). If an application is designed to coexist in other applications in the save VM it should never ever attempt to call it.

Returning from main(..) method may or may not terminate the VM depending on the circumstances - when there active threads with non-deamon status the VM will continue. System.exit(..) causes all threads (deamon & not) to terminate by throwing ThreadDeath error in their current frame. A misbehaving thread may still catch ThreadDeath, but after an attempt to stop the applicaiton threads is made and other clean up actitities are completed (finalizers, shutdown hooks, delete-on-exit files), the VM will do System.abort(..).

It is also possible to call System.abort(..) directly, but it's not a good idea under most circumstances.

Application containers usually prevent stopping the VM by application code using java.security mechanism, so System.exit(..) is a concern only for standalone/desktop applications.

Hope this helps
Rafal


Back to the top