What would happen if someone writes System.exit()
in a servlet would the server or the application crash?
exit() method exits current program by terminating running Java virtual machine. This method takes a status code. A non-zero value of status code is generally used to indicate abnormal termination.
In Java exit() method is in java. This System. exit() method terminates the current JVM running on the system which results in termination of code being executed currently. This method takes status code as an argument.
because invoking System. exit() kills your JVM, invoking this from Tomcat or Jetty, will not only kill your application but the most likely server itself. This can be potentially dangerous if that server also hosts other critical applications, which is not uncommon at all.
halt() The Runtime class allows an application to interact with the environment in which the application is running. It has a halt method that can be used to forcibly terminate the running JVM. Unlike the exit method, this method does not trigger the JVM shutdown sequence.
Maybe! The container should have modified the security manager (SecurityManager.checkExit()
) so the call may result in an AccessControlException
. No webapp should be able to shutdown the server.
There is an answer to this question already here: http://tomcat.apache.org/tomcat-5.5-doc/security-manager-howto.html
The JVM running the servlet container would terminate, so, yes.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With