This week's book giveaway is in the Cloud/Virtualizaton forum.
We're giving away four copies of Mesos in Action and have Roger Ignazio on-line!
See this thread for details.
Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

After calling destroy method in servlet

 
Madhu GM
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

I have written a servlet code and tried to call the servlet's destroy method. Now I can able to call the destroy method.
What happens after i call that method ?.. weather it will remove the servlet ?.. if not what it will do ?..

Thanks
Madhu
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The destroy method is intended to be called by the servlet container. It's not something you would want to call your self.

It's a place for you to put cleanup code, if necessary.
 
Madhu GM
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I agree with you Ben ..

But want to know what happens when u call the the destroy methos rather than the container ..
 
Adeel Ansari
Ranch Hand
Posts: 2874
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just make a call to destroy yourself. Believe me nothing is gonna happen. And if you override the destroy method and inside that place something like,

System.out.println("hey i got a call");

then you will get it printed, but nothing else. As Ben said, "its a place for you to put a cleanup code, if necessary".

cheers.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Looks like it does nothing.
It's there for you to override and put your cleanup code in.

Quote from the Servlet Specs SRV.14.2.6.1

destroy()
public void destroy()
Called by the servlet container to indicate to a servlet that the servlet is being taken out of service. This method is only called once all threads within the servlet's service method have exited or after a timeout period has passed. After the servlet container calls this method, it will not call the service method again on this servlet. This method gives the servlet an opportunity to clean up any resources that are being held (for example, memory, file handles, threads) and make sure that any persistent state is synchronized with the servlet's current state in memory.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Adeel Ansari,
Our posts crossed....
 
Adeel Ansari
Ranch Hand
Posts: 2874
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Ben Souther:
Adeel Ansari,
Our posts crossed....


 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic