load-on-startup is a tag element which appear inside servlet tag in web.xml.load-on-startup tells the web container about loading of a particular servlet. if you don’t specify load-on-startup then container will load a particular servlet when it feels necessary most likely when first request for that servlet will come, this may lead to longer response time for that query if Servlet is making database connection which contribute network latency or time consuming job.

 <servlet>
   <servlet-name>StartUpServlet</servlet-name>
   <servlet-class>com.mugil.tutor.ConfigServlet</servlet-class>
   <load-on-startup>1</load-on-startup>
  </servlet>

Points to remember

  • If load-on-startup value is same for two servlet than they will be loaded in an order on which they are declared inside web.xml file.
  • If load-on-startup is 0 or negative integer than Servlet will be loaded when Container feels to load them.
  • load-on-startup guarantees loading, initialization and call to init() method of servlet by web container.
  • If there is no load-on-startup element for any servlet than they will be loaded when web container decides to load them.

Lower the value of load-on-startup, servlet will be loaded first.

Use during Connection pool, downloading files or data from network or prepare environment ready for servicing client in terms of initializing cache, clearing pipelines and loading important data in memory

Comments are closed.