Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

destroying the servlet

 
Shreenivaas Reddy
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
how many ways we can destroy the servlet in our program?
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What do you mean by "destroy" the servelt?
 
Ulf Dittmer
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Not sure what exactly you're trying to do, but a web application does not concern itself with the lifecycle of servlets - the servlet container does.
 
ankur rathi
Ranch Hand
Posts: 3830
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Though you don't destroy a servlet, it's the job of container.

But if you will call System.exit() or you will shutdown the server then container will destroy the all the servlets... Right??? :roll:
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13071
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If what you want is to prevent a servlet from responding to requests, have it throw a javax.servlet.UnavailableException - the container will then reject requests.
In the Tomcat servlet engine you can use the Manager interface to stop, start or reload an entire "web application" - which might be many servlets and jsp.
In case you are wondering, the destroy() method is part of the servlet life cycle controled by the container and should never be called by your program. It exists so you can clean up resources used by the servlet when the container is removing the instance for some reason.
Bill
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by rathi ji:
Though you don't destroy a servlet, it's the job of container.

But if you will call System.exit() or you will shutdown the server then container will destroy the all the servlets... Right??? :roll:


Yes, and blowing the server up with a stick of dynamite will also destroy the servlet.
Neither would be a reasonable approach.
 
Ulf Dittmer
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sure, restarting the container (or even just the web app) will unload the servlets. Calling System.exit will not work if the container is running with a security manager, though.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic