Wednesday, November 09, 2005

When init() method is called?

Options would be

(a) init method will be executed immediately after loading and instantiation of the servlet class takes place.

(b) Container differs the initialization till the first client asks for service.

Servlet Specification doesn't state exactly when init method should be called. But it will be called surely before servlet can serve to its first request.

From Servlet Spec

After the servlet object is instantiated, the container must initialize the servlet before it can handle requests from clients.

Instantiation ==> Calling the no-arg’s constructor of the servlet class.

Initialization ==> Calling the init() method.

Servlet initialization can also be done at server start-up by configuring in DD by setting positive integer value, to load the servlet at startup.

Hence it is wiser to answer as init() method will be execute when the servlet class is loaded by the container.

0 Comments:

Post a Comment

<< Home