We know about the servlet life cycle which is controlled by the servlet container. The servlet lifecycle goes thought he following phases:
1.)Loading of servlet class
2.)Creating instance of servlet
3.)Initialization of servlet by servlet container by calling init() method.
4.)Execution of service.
5.)Destroying of the servlet
2.)Creating instance of servlet
3.)Initialization of servlet by servlet container by calling init() method.
4.)Execution of service.
5.)Destroying of the servlet
By default a servlet container doesn't initialize the servlets when it starts up rather it initializes it when it receives a request for that servlet first time. This is called lazy loading.
However if we want our servlets to be initialized as soon as the container starts up , there is an another way to do so. The servlet specification defines element, which can be specified in the deployment descriptor to make the servlet container load and initialize the servlet as soon as it starts up.
However if we want our servlets to be initialized as soon as the container starts up , there is an another way to do so. The servlet specification defines element, which can be specified in the deployment descriptor to make the servlet container load and initialize the servlet as soon as it starts up.
For eg.- <load-on-startup> tag can be used in web.xml. This makes the java servlet to be loaded and initialized when the server starts. This process of loading a java servlet before receiving any request is called preloading or preinitialization of a servlet.