• 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

Question about the init() method.

 
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
According to the API if a servlet does not implement SingleThreadModel then only one instance of it is created and mutiple threads share this instance. Whenever the container loads the servlet, it initializes it, calling the init() method on that instance.

However, in cases of high load, the container may also instantiate multiple instances of the servlet. In this case, will init() be called on each of the instances ?
 
Gaurav Sahni
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Nobody to help??? :roll:

Let me make the question a bit simple.

Suppose i have written a servlet which is handling the client request and doing some database manipulations based on it. Obviously, i would use the init method to open the database connection, and perform other initializations(if any).

Now, the question is suppose the no. of requests are v.high, and one instance of the servlet might not be able to serve all the threads. therefore, the container might decide to create multiple instances of the same servlet. In such a case, would the init() method be called on each instance of the servlet ?

Regards,
Gaurav.
 
Ranch Hand
Posts: 200
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You have answered your own question.



Whenever the container loads the servlet, it initializes it, calling the init() method on that instance.

 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic