File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Servlets and the fly likes How to shut down container from within my servlet? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "How to shut down container from within my servlet?" Watch "How to shut down container from within my servlet?" New topic

How to shut down container from within my servlet?

Philippe Desrosiers
Ranch Hand

Joined: Mar 29, 2006
Posts: 138
Yeah, Iknow, seems like a ridiculous question, right? WhenI start Tomcat (5.5.15), and Tomcat starts my servlet, I want to be able to shut down the Tomcat container from code if there is no work to be done (ie: the servlet was not properly configured, or the database doesn't exist, or something).

Is there any way my servlet can shut down it's own container?
Ben Souther

Joined: Dec 11, 2004
Posts: 13410

Why would you want to do such a thing?
Do you have no other access to the machine that your server is running under?

Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
dema rogatkin
Ranch Hand

Joined: Oct 09, 2002
Posts: 294
Try System.exit(..), however security manager can not allow this for a servlet. Most of servlet containers have admin web UI, so your servlet can use it to shutdown servlet container.

Tough in space?, <a href="" target="_blank" rel="nofollow">Get J2EE servlet container under 150Kbytes here</a><br />Love your iPod and want it anywhere?<a href="" target="_blank" rel="nofollow">Check it here.</a><br /><a href="" target="_blank" rel="nofollow">Curious about generic in Java?</a><br /><a href="" target="_blank" rel="nofollow">Hate ant? Use bee.</a><br /><a href="" target="_blank" rel="nofollow">Need contacts anywhere?</a><br /><a href="" target="_blank" rel="nofollow">How to promote your business with a search engine</a>
I agree. Here's the link:
subject: How to shut down container from within my servlet?
It's not a secret anymore!