Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

When init() method is called?

 
Veena Pointi
Ranch Hand
Posts: 442
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When servlet is instantiated and init() method is called ?In book it is given before first client request,that means when we start the server?
 
Martyn Clark
Ranch Hand
Posts: 108
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Veena
It maybe when the web app is loaded or when servlet is first called and it can not service any requests until after the init() method is complete.
 
Veena Pointi
Ranch Hand
Posts: 442
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks.Yeah,figured out it is done either during container start up or first request.This is container specific.
 
Abhijeet Kadam
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
init() is called either at web container start up or first request but there are some protocals which insure that it is called at startup
SCJP 1.4
 
Narendra Dhande
Ranch Hand
Posts: 951
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

If the <servlet> element has a <load-on-startup> then the servlet is initialized at the time of server startup/(re-)deployment of application. At this time the init() method is called. Other-wise prior to first request is received for this servlet.

Thanks
 
Deepti Padiyar
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Even if <load-on-startup> is not specified in the DD, it depends on the web-container when it wnats to load the servlet class, either when the server is started, at startup , or when the first request comes in. My servlet's init() method is called whne the server starts up even when it does not have any <load-on-startup> associated with it.
[ July 12, 2006: Message edited by: Sumita Padiyar ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic