How do I close a servlet container from a servlet?

Is there a portable way to request the servlet container to shutdown gracefully from within the servlet?

By portable I mean a technique that will work on all standard compatible containers (Tomcat, Jetty, Winstone, etc.).

Note that this is the opposite of the Servlet.destroy () method, which is called when the container takes a servlet.

+2


source to share


2 answers


System.exit ();

If you are working without SecurityManager.

EDIT: Is it graceful? It depends on the containers.



In Tomcat if you call it 0

  System.exit(0);

      

It's as elegant as shutdown.sh or Catalina.stop (), because the stop hook just calls stop ().

+1


source


In Java EE Servlet Spec, I don't know what I should know about, what should be portable for it.

Link it to the Servlet API specifications, so if there is such a way, it will be documented somewhere.



I also agree that it would be a very bad idea for one servlet to be able to close the container!

+4


source







All Articles