Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

System.exit in servlet

What would happen if someone writes System.exit() in a servlet would the server or the application crash?

like image 269
vaibhav Avatar asked May 20 '10 07:05

vaibhav


People also ask

What is the use of system exit?

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.

What is System exit Java?

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.

Why we should not use system exit ()?

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.

What is alternative to system exit?

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.


3 Answers

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.

like image 65
Arne Burmeister Avatar answered Nov 08 '22 02:11

Arne Burmeister


There is an answer to this question already here: http://tomcat.apache.org/tomcat-5.5-doc/security-manager-howto.html

like image 27
J K Avatar answered Nov 08 '22 00:11

J K


The JVM running the servlet container would terminate, so, yes.

like image 2
aioobe Avatar answered Nov 08 '22 00:11

aioobe