Tomcat Source (original) loaded by servlet at startup

Source: Internet
Author: User

Tomcat 8.0.36

Knowledge Points:

    • By configuring Loadonstartup, you can set whether the servlet will load at tomcat startup and load sequentially by value, with a minimum valid value of 0 and a maximum valid value of Integer.max_value.
    • The class of the JSP servlet is Org.apache.jasper.servlet.JspServlet.
    • The maximum valid value is used when a Jsp servlet is forced to load at startup, its loadonstartup default value, or its value is a failure value.
    • By configuring the Failctxifservletstartfails property value of the context or host, first use context, set whether the thrown Servletexception exception is ignored when the servlet is loaded when Tomcat starts, If not ignored, Tomcat fails to start and is not ignored by default.

Explanation Source:

When Tomcat starts, it calls Loadonstartup, and the passed parameter is an array of container[]. This array represents an array of information, such as the servlet, that is configured from our web.xml,web-fragment.xml, annotations, and dynamically added methods.

OK set to False to indicate that Tomcat failed to start and will not work. That is, the return value of Loadonstartup will affect whether Tomcat works.

if (! Loadonstartup (Findchildren ())) {    false;}

After entering the Loadonstartup method, a treemap is defined first, and the main purpose of using TreeMap is to sort.

It then traverses the servlet information set, translating the servlet information in the traversal into the actual type wrapper.

The Getloadonstartup method is used to get the start order level of the servlet, filtering out the servlet with a starting order level of less than 0.

Next, add the start order level greater than or equal to 0 to TreeMap, the value of the map is a wrapper table, that is, the servlet bins are loaded into the box of the owning boot order level.

Treemap<integer, arraylist<wrapper>> map =NewTreemap<>(); for(inti = 0; i < children.length; i++) {Wrapper Wrapper=(Wrapper) children[i]; intLoadonstartup =Wrapper.getloadonstartup (); if(Loadonstartup < 0)        Continue; Integer Key=integer.valueof (Loadonstartup); ArrayList<Wrapper> list =Map.get (key); if(List = =NULL) {List=NewArraylist<>();    Map.put (key, list); } list.add (wrapper);}

First enter the Getloadonstartup method, where the default value of the member variable Loadonstartup is-1, The member variable Isjspservlet is the class that records the configuration of the servlet that is not Org.apache.jasper.servlet.JspServlet, a servlet is not a JSP servlet to see if its class is not.

To put it simply, the default value of the normal servlet's startup order level is-1, the minimum valid value is 0, and the maximum valid value is Integer.max_value. The default value for the startup order level of a JSP servlet is the maximum value, and the valid value is consistent with the normal servlet, and the maximum value is used when its value is invalidated.

 Public int Getloadonstartup () {    if (isjspservlet && loadonstartup < 0) {          return  integer.max_value;     Else {        return (this. loadonstartup);    }}

Back in the original Getloadonstartup method, the map has loaded the servlet that needs to be launched into a box that is ordered by the start order, followed by the sequence of start-up sequence, then the order of the servlet, and then the load method is executed.

If the Load method throws an Servletexception exception, the getcomputedfailctxifservletstartfails gets the value to decide whether or not to let Tomcat boot fail.

The value obtained is the Failctxifservletstartfails property of the context configuration, and if the property is not configured, the property of the Failctxifservletstartfails is configured with the host, and its default value is False.

 for (arraylist<wrapper> list:map.values ()) {    for  (Wrapper wrapper:list) {          Try  {            wrapper.load ();         Catch (servletexception e) {            if  (Getcomputedfailctxifservletstartfails ()) {                 return false ;            }        }    }} return true;

Tomcat Source (original) loaded by servlet at startup

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.