"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