What Is Load-On-Startup Servlet Chemical Component Division Inwards Web.Xml Alongside Example?
load-on-startup is an chemical cistron which appears within <servlet> tag in web.xml.4 years dorsum load-on-startup was a real pop servlet interview question because non many Java J2EE developer was familiar amongst this chemical cistron as well as how load-on-startup industrial 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 cistron as well as what are dissimilar values nosotros tin configure for loadOnStartup within web.xml.
What is load-on-startup
database connections or performing ldap authentication which contribute network latency or whatsoever other fourth dimension consuming job, to avoid this, spider web container provides y'all a hateful to specify certainly 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 specify whatsoever value to this chemical cistron merely inwards instance of load-on-startup>0 , servlet amongst less publish volition hold out loaded first. For instance inwards below web.xml AuthenticationServlet volition hold out loaded earlier AuthorizationServlet because load-on-startup value for AuthenticationServlet is less (2) field for AuthorizationServlet is 4.
load-on-startup Example inwards web.xml
hither is an instance of how to role charge on startup tag within servlet chemical cistron 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 lodge 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 as well as telephone telephone to init() method of servlet yesteryear spider web container.
4. If at that spot is no <load-on-startup> chemical cistron for whatsoever 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 environs laid upward for servicing customer inwards damage of initializing cache , clearing pipelines as well as loading of import information inwards memory. If whatsoever of your servlet performs these jobs thus declare them using <load-on-startup> chemical cistron as well as specify lodge every bit per your concern logic or what suites your application. Remember lower the value of <load-on-startup>, servlet volition hold out loaded first. You tin too 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 cistron inwards web.xml. Use it carefully as well as it tin trim response fourth dimension for your spider web application. You tin too cheque my Struts interview questions as well as spring interview questions for to a greater extent than on J2EE interview.
Further Learning
Spring Framework 5: Beginner to Guru
Difference betwixt SendRedirect as well as Forward inwards Servlet?
Difference betwixt HashMap as well as HashSet inwards Java
Belum ada Komentar untuk "What Is Load-On-Startup Servlet Chemical Component Division Inwards Web.Xml Alongside Example?"
Posting Komentar