Reputation: 17777
Is there a portable way to request a Servlet container to shutdown gracefully, from within a servlet?
By portable I mean a technique that will work on all standard compliant containers (Tomcat, Jetty, Winstone, etc).
Note that this is the opposite of the Servlet.destroy() method, which gets called when the container is taking the servlet down.
Upvotes: 2
Views: 2515
Reputation: 75466
System.exit();
If you are running with no SecurityManager.
EDIT: Is this graceful? This depends on containers.
On Tomcat, if you call it with 0
System.exit(0);
It's as graceful as shutdown.sh or Catalina.stop() because the shutdown hook simply calls stop().
Upvotes: 1
Reputation: 43560
There's no way defined in the Java EE Servlet Spec that I know of, which there would need to be for it to be portable.
The link it to the servlet API specs, so if there's such a way, it'll be documented there somewhere.
I also agree that it'd be a really bad idea for one servlet to be able to shut down the container!
Upvotes: 4