What Is Load-On-Startup Servlet Chemical Component Inwards Web.Xml Amongst Example?
load-on-startup is an chemical ingredient 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 ingredient together with 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 operate load-on-startup chemical ingredient together with what are dissimilar values nosotros tin laissez passer on the axe configure for loadOnStartup within web.xml.
What is load-on-startup
If you lot specify load-on-startup parameter within a servlet than based upon its value Container volition charge it.you tin laissez passer on the axe specify whatever value to this chemical ingredient merely inwards instance of load-on-startup>0 , servlet amongst less divulge volition endure loaded first. For illustration inwards below web.xml AuthenticationServlet volition endure loaded earlier AuthorizationServlet because load-on-startup value for AuthenticationServlet is less (2) spell for AuthorizationServlet is 4.
load-on-startup Example inwards web.xml
hither is an illustration of how to operate charge on startup tag within servlet chemical ingredient 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 ii servlet than they volition endure loaded inwards an guild on which they are declared within web.xml file.
2. if <load-on-startup> is 0 or negative integer than Servlet volition endure loaded when Container feels to charge them.
3. <load-on-startup> guarantees loading, initialization together with telephone vociferation upwards to init() method of servlet past times spider web container.
4. If at that spot is no <load-on-startup> chemical ingredient for whatever servlet than they volition endure loaded when spider web container decides to charge them.
When to operate <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 gear upwards surround cook for servicing customer inwards damage of initializing cache , clearing pipelines together with loading of import information inwards memory. If whatever of your servlet performs these jobs hence declare them using <load-on-startup> chemical ingredient together with specify guild every bit per your describe concern logic or what suites your application. Remember lower the value of <load-on-startup>, servlet volition endure loaded first. You tin laissez passer on the axe likewise cheque your spider web container documentation on how precisely charge on start-up is supported.
That’s all on charge on start-up tag of servlet chemical ingredient inwards web.xml. Use it carefully together with it tin laissez passer on the axe cut back response fourth dimension for your spider web application. You tin laissez passer on the axe likewise cheque my Struts interview questions together with spring interview questions for to a greater extent than on J2EE interview.
Further Learning
Spring Framework 5: Beginner to Guru
Difference betwixt SendRedirect together with Forward inwards Servlet?
Difference betwixt HashMap together with HashSet inwards Java
Komentar
Posting Komentar