• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

overloading of init-service and destroy methods

 
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 1704
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 294
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic