What would happen i开发者_JS百科f someone writes System.exit()
in a servlet would the server or the application crash?
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.
Well, System.exit()
will terminate the current running JVM. So it is likely that the code written in servlet containers' addShutdownHook
will be triggered.
No you cannot because it will throw a security exception.
From https://javarevisited.blogspot.in/2014/11/dont-use-systemexit-on-java-web-application.html:
System.exit() in Java Web application, which runs inside either web server or application server, which itself is Java program is not a good idea to use it at all. Why? because invoking System.exit() kills your JVM, invoking this from Tomcat or Jetty, will not only kill your application but most likely server itself. This can be potentially dangerous, if that server also host other critical application, which is not uncommon at all. As per my experience, System.exit() calls are quite common in overly broad try-catch blocks in web application start-up code that loads environment variables, properties files, connect to MQ Series, establishes database connection, opens socket connections, etc. This is still ok, if you are writing core Java based server, where each application has their own JVM, but with web application deployed on Tomcat, JBoss, WebSphere, Weblogic or any other application server, using System.exit() is big mistake. In worst case can result in outage for lots of other critical application. On the other hand, there are ways to prevent your web application from someone else’s mistake, by enabling Security Manager. System.exit() and Runtime.exit() both goes through the security manager. Enabling Security manager will catch these calls and reduce them into an exception rather than shutting down the whole VM.
System.exit() will shutdown the Server running Application ( tested on tomcat 7 ).
System.exit() is closing the particular application in that browser
精彩评论