• 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

How to find if the servlet is newly created or it was already existing

 
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Dear All
I was ask this question at an interview. But i do not know whether it is possible or not. Can anyone help. The interviewer asked me "how will you find out that the servlet was already existing or is newly created".

Thanks and Regards
Pankaj Tiwari
 
Ranch Hand
Posts: 893
Tomcat Server Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
When a servlet is newly created it's init() method will be called
 
Pankaj Tiwari
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thats what i told..but he did not appeared to be very satisfied with answer [ ]
 
Ranch Hand
Posts: 3389
Mac MySQL Database Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I also would go with 'init()' methods invocation thats where we developers would get to know as and when a servlet is instantiated and invoked.

If at all, we can have a workaround by using some date/time variables being set as and when the servlet is invoked ,and whenever required you can retrieve that information.

I think this would be of some little help! Other ranchers any suggestions here?
 
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
putting some s.o.p line in init method would have notified in console that servlet is newly created else if request comes if sop line doesnot get printed then its an existing one
 
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It is also possible to track the usage of the Class via either a static or instance block in the code or even the no-arg constructor, but as has been mentioned above, I'd still prefer to do it in the init() method.
 
Ranch Hand
Posts: 3852
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I forgot the available listeners. Can any listener do the trick???
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Have you looked?
 
Pankaj Tiwari
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
ContextListeners is what i can think of but it is for an application. Called everytime application is reloaded.
 
Remko Strating
Ranch Hand
Posts: 893
Tomcat Server Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I don't know for sure if in the standard spec there is defined a listener for the event life cycle of servlets.

On the net I found that IBM has implemented a listener for servlets


Interface ServletListener
reply
    Bookmark Topic Watch Topic
  • New Topic