What Is Load-On-Startup Servlet Chemical Cistron Inwards Web.Xml Amongst Example?

load-on-startup is an chemical component division which appears within <servlet> tag in web.xml.4 years dorsum load-on-startup was a rattling pop servlet interview question because non many Java J2EE developer was familiar amongst this chemical component division in addition to how load-on-startup plant within servlet container similar tomcat or webshere. In this J2EE Tutorial nosotros volition run across what is charge on start up, how to role load-on-startup chemical component division in addition to what are unlike values nosotros tin dismiss configure for loadOnStartup within web.xml.

What is load-on-startup
EE developer was familiar amongst this chemical component division in addition to  What is load-on-startup servlet chemical component division inwards web.xml amongst Example?database connections or performing ldap authentication which contribute network latency or whatever other fourth dimension consuming job, to avoid this, spider web container provides y'all a hateful to specify sure enough servlet to hold out loaded during deployment fourth dimension of application yesteryear using load-on-startup parameter.

If y'all specify load-on-startup parameter within a servlet than based upon its value Container volition charge it.you tin dismiss specify whatever value to this chemical component division just inwards illustration of load-on-startup>0 , servlet amongst less give away volition hold out loaded first. For illustration inwards below web.xml AuthenticationServlet volition hold out loaded earlier AuthorizationServlet because load-on-startup value for AuthenticationServlet is less (2) piece for AuthorizationServlet is 4.



load-on-startup Example inwards web.xml

hither is an illustration of how to role charge on startup tag within servlet chemical component division inwards web.xml:

<servlet>
<servlet-name>AuthenticationServlet</servlet-name>
<display-name>AuthenticationServlet</display-name>
<servlet-class>com.trading.AuthenticationServlet</servlet-class>
<load-on-startup>2</load-on-startup>
</servlet>

<servlet>
<servlet-name>AuthorizationServlet</servlet-name>
<display-name>AuthorizationServlet</display-name>
<servlet-class>com.trading.AuthorizationServlet</servlet-class>
<load-on-startup>4</load-on-startup>
</servlet>

Important points on load-on-startup element

1. If <load-on-startup> value is same for 2 servlet than they volition hold out loaded inwards an fellowship on which they are declared within web.xml file.
2. if <load-on-startup> is 0 or negative integer than Servlet volition hold out loaded when Container feels to charge them.
3. <load-on-startup> guarantees loading, initialization in addition to telephone band to init() method of servlet yesteryear spider web container.
4. If in that place is no <load-on-startup> chemical component division for whatever servlet than they volition hold out loaded when spider web container decides to charge them.

When to role <load-on-startup> inwards web.xml
<load-on-startup> is suitable for those servlet which performs fourth dimension consuming jobs e.g. Creating Database Connection pool, downloading files or information from network or prepare surroundings gear upwardly for servicing customer inwards damage of initializing cache , clearing pipelines in addition to loading of import information inwards memory. If whatever of your servlet performs these jobs in addition to then declare them using <load-on-startup> chemical component division in addition to specify fellowship every bit per your trouble concern logic or what suites your application. Remember lower the value of <load-on-startup>, servlet volition hold out loaded first. You tin dismiss likewise cheque your spider web container documentation on how just charge on start-up is supported.


That’s all on charge on start-up tag of servlet chemical component division inwards web.xml. Use it carefully in addition to it tin dismiss cut response fourth dimension for your spider web application. You tin dismiss likewise cheque my Struts interview questions in addition to spring interview questions for to a greater extent than on J2EE interview.

Further Learning
Spring Framework 5: Beginner to Guru
Difference betwixt SendRedirect in addition to Forward inwards Servlet?
Difference betwixt HashMap in addition to HashSet inwards Java

Sumber https://javarevisited.blogspot.com/

0 Response to "What Is Load-On-Startup Servlet Chemical Cistron Inwards Web.Xml Amongst Example?"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel