aspose file tools*
The moose likes Servlets and the fly likes overloading of init-service and destroy methods Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "overloading of init-service and destroy methods" Watch "overloading of init-service and destroy methods" New topic
Author

overloading of init-service and destroy methods

devayani Devasthali
Ranch Hand

Joined: Aug 25, 2005
Posts: 40
hello All,
I am writing simple servlets .can anybody pls help in understanding the concepts?
Please correct me wherever I am wrong.
thanx in advance
actually, I have overrided init , service and destroy
now doGet will not be called automatically hence I called that explicitly inside service..
now inside service , first I have called destroy method then doget ()
logically, either I must get exception or it should not called doGet method once servlet's destroy method is called.
but practically,called both service - destroy and then doget method ...
can anybody pls clear my doubt ?
am I going wrong somewhere?
pls do reply asap.
thanx & regards
Devayani
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42612
    
  65
You should never call destroy, just like you should never call init. The servlet container calls these when a servlet is created or removed. Apart from that it sounds OK.


Ping & DNS - my free Android networking tools app
Kj Reddy
Ranch Hand

Joined: Sep 20, 2003
Posts: 1704
If you call destroy() from service() method it becomes just an ordinary method call. It wont really unload the servlet, it will be only unloaded when the destroy method called by servlet contained and we wont have control on when it need to be unloaded.

You should never call destroy or init methods.
[ February 15, 2006: Message edited by: KJ Reddy ]
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

You might want to read up on the service method as well.
There is generally never a need to override it when doing normal application coding with Servlets.

In short the service method, analyses the request and calls the appropriate method (doPost, doGet, doHead, etc...) depending on type of the request. Overriding it short circuts this process.


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Bruno Boehr
Greenhorn

Joined: Feb 15, 2006
Posts: 17
devayani Dev,

In addition to what the previous commenters have said, I would suggest that you describe your situation and tell us what effect you are trying to achieve by calling the destroy() method from inside service(). Chances are, a better solution might pop up


<a href="http://webjavenue.com/" target="_blank" rel="nofollow">Your first website in Java: easier than you think</a>
dema rogatkin
Ranch Hand

Joined: Oct 09, 2002
Posts: 294
It looks like you need also play with java itself a bit. For some reason you have impression that when you call some methods of your class, all other classes can notice that. For example if you define a method with name flyGrog and call it, you will surprise that no flying frogs happen after.


Tough in space?, <a href="http://tjws.sf.net" target="_blank" rel="nofollow">Get J2EE servlet container under 150Kbytes here</a><br />Love your iPod and want it anywhere?<a href="http://mediachest.sf.net" target="_blank" rel="nofollow">Check it here.</a><br /><a href="http://7bee.j2ee.us/book/Generics%20in%20JDK%201.5.html" target="_blank" rel="nofollow">Curious about generic in Java?</a><br /><a href="http://7bee.j2ee.us/bee/index-bee.html" target="_blank" rel="nofollow">Hate ant? Use bee.</a><br /><a href="http://7bee.j2ee.us/addressbook/" target="_blank" rel="nofollow">Need contacts anywhere?</a><br /><a href="http://searchdir.sourceforge.net/" target="_blank" rel="nofollow">How to promote your business with a search engine</a>
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: overloading of init-service and destroy methods