Analysis of the Tomcat (supplement) Httpconnector.initialize () and Start () methods and the Standardcontext.start () method

Source: Internet
Author: User
Tags wrappers

"0" README

0.0) Background of the source code in this article, see Tomcat (9) Session Management

0.1) This paper mainly in the form of pictures to analyze their approximate call process;

0.2) HttpConnector = = Org.apache.catalina.connector.http.HttpConnector; and standardcontext = = Org.apache.catalina.core.StandardContext;

0.3) The source code for the application is as follows:

Public final class Bootstrap {public static void main (string[] args) {system.setproperty ("catalina.base", System.get    Property ("User.dir"));    Connector Connector = new HttpConnector ();    Wrapper wrapper1 = new Simplewrapper ();    Wrapper1.setname ("Session");    Wrapper1.setservletclass ("Sessionservlet");    Context context = new Standardcontext ();    Context.setpath ("/myapp");    Context.setdocbase ("myApp");    Context.addchild (Wrapper1);    Context.addservletmapping ("/myapp/session", "Session");    Lifecyclelistener listener = new Simplecontextconfig ();    ((Lifecycle) context). Addlifecyclelistener (listener);    Loader Loader = new Webapploader ();    Context.setloader (loader);    Connector.setcontainer (context);    Manager Manager = new Standardmanager ();    Context.setmanager (manager);      try {connector.initialize ();//Highlight line. ((Lifecycle) connector). Start ();      Highlight Line. ((Lifecycle) context). Start ();      Highlight Line. Make the ApplicatIon wait until we press a key.      System.in.read ();    ((Lifecycle) context). Stop ();    } catch (Exception e) {e.printstacktrace (); }  }}

"1" httpconnector.initialize ()



"2" Httpconnector.start ()



"3" Standardcontext.start ()



/** * Load and initialize all Servlets marked ' load on startup ' in the ' Web application Deployment Descriptor. * * @param children Array of wrappers for all currently defined * Servlets (including those not declared load On startup) */public void Loadonstartup (Container children[]) {//Org.apache.catalina.core.StandardContext.loadOn        StartUp ().        Collect "Load on startup" Servlets, need to be initialized TreeMap map = new TreeMap ();            for (int i = 0; i < children.length; i++) {Wrapper Wrapper = (Wrapper) children[i];            int loadonstartup = Wrapper.getloadonstartup ();            if (Loadonstartup < 0) continue;            if (Loadonstartup = = 0)//arbitrarily put them last loadonstartup = Integer.max_value;            Integer key = new Integer (loadonstartup);            ArrayList list = (ArrayList) map.get (key); if (list = = null) {list = new ArraylIST ();            Map.put (key, list);        } list.add (wrapper);        }//Load the collected "load on startup" Servlets Iterator keys = Map.keyset (). Iterator ();            while (Keys.hasnext ()) {integer key = (integer) keys.next ();            ArrayList list = (ArrayList) map.get (key);            Iterator wrappers = List.iterator ();                while (Wrappers.hasnext ()) {Wrapper Wrapper = (Wrapper) wrappers.next ();                try {wrapper.load ();                                     } catch (Servletexception e) {log (sm.getstring ("Standardwrapper.loadexception"),                    GetName ()), e); Note:load errors (including a servlet, throws//unavailableexception from THT init () method) a Re not//fatal to Application Startup}}}


Analysis of the Tomcat (supplement) Httpconnector.initialize () and Start () methods and the Standardcontext.start () method

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.