Wrapper ´ú±íÒ»¸ö Servlet£¬Ëü¸ºÔð¹ÜÀíÒ»¸ö Servlet£¬°üÀ¨µÄ Servlet µÄ×°ÔØ¡¢³õʼ»¯¡¢Ö´ÐÐÒÔ¼°×ÊÔ´»ØÊÕ¡£ËüµÄ¸¸ÈÝÆ÷Ò»°ãÊÇContext£¬Wrapper ÊÇ×îµ×²ãµÄÈÝÆ÷£¬ËüûÓÐ×ÓÈÝÆ÷ÁË£¬ËùÒÔµ÷ÓÃËüµÄ addChild ½«»áÅ×illegalargumentexception¡£Wrapper µÄʵÏÖÀàÊÇ StandardWrapper£¬StandardWrapper »¹ÊµÏÖÁËÓµÓÐÒ»¸ö Servlet ³õʼ»¯ÐÅÏ¢µÄ ServletConfig£¬ÓÉ´Ë¿´³ö StandardWrapper ½«Ö±½ÓºÍ Servlet µÄ¸÷ÖÖÐÅÏ¢´ò½»µÀ¡£
ÔÚStandardContextÆô¶¯Ê±£¬¶ÁÈ¡web.xmlÅäÖÃÎļþ£¬ÅäÖÃContextÖ®ºó£¬½ô½Ó×ÅÆô¶¯ContextµÄһЩ¸½Êô×é¼þ£¬³ý´ËÒÔÍ⻹¼ÓÔØÁËÄÇЩ±ê¼ÇΪ"load on start"µÄÄÇЩwrapper
-
-
if (ok) {
-
loadOnStartup(findChildren());
-
}
-
public void loadOnStartup(Container children[]) {
-
-
-
TreeMap<Integer, ArrayList<Wrapper>> map =
-
new TreeMap<Integer, ArrayList<Wrapper>>();
-
for (int i = 0; i < children.length; i++) {
-
Wrapper wrapper = (Wrapper) children[i];
-
int loadOnStartup = wrapper.getLoadOnStartup();
-
if (loadOnStartup < 0)
-
continue;
-
Integer key = Integer.valueOf(loadOnStartup);
-
ArrayList<Wrapper> list = map.get(key);
-
if (list == null) {
-
list = new ArrayList<Wrapper>();
-
map.put(key, list);
-
}
-
list.add(wrapper);
-
}
-
-
-
for (ArrayList<Wrapper> list : map.values()) {
-
for (Wrapper wrapper : list) {
-
try {
-
wrapper.load();
-
} catch (ServletException e) {
-
getLogger().error(sm.getString("standardWrapper.loadException",
-
getName()), StandardWrapper.getRootCause(e));
-
-
-
-
}
-
}
-
}
-
-
}
Õâ¸ö·½·¨×öÁËÁ½¼þÊ£º
1¡¢±éÀúÕâЩwrapper,½«Æä·ÅÈëÒ»¸ömapÖС£keyΪÆô¶¯Ë³Ðò£¬valueÊÇͬһÆô¶¯Ë³ÐòµÄservlet list£¬ÎªÁ˱£»¤Êý×ÖСµÄÏÈÆô¶¯£¬ÕâÀïÓÃÁËtreemapÕâÖÖÊý¾Ý½á¹¹À´´æ´¢£»
2¡¢±éÀúÕâ¸ömap£¬ÒÀ´Î¼ÓÔضÔÓ¦listÖеĸ÷¸öwrapper¡£ÓÉÓÚ²ÉÓõÄÊÇarrayList£¬ËùÒÔÏàͬ"load on start"Öµ¿¿Ç°µÄÏȼÓÔØ
ÏÂÃæÀ´¿´¿´StandardWrapperµÄload·½·¨£¬Ö±½Óµ÷ÓÃÁËloadServlet·½·¨À´³õʼ»¯
-
public synchronized void load() throws ServletException {
-
instance = loadServlet();
-
-
if (!instanceInitialized) {
-
initServlet(instance);
-
}
-
-
if (isJspServlet) {
-
StringBuilder oname =
-
new StringBuilder(MBeanUtils.getDomain(getParent()));
-
-
oname.append(":type=JspMonitor,name=");
-
oname.append(getName());
-
-
oname.append(getWebModuleKeyProperties());
-
-
try {
-
jspMonitorON = new ObjectName(oname.toString());
-
Registry.getRegistry(null, null)
-
.registerComponent(instance, jspMonitorON, null);
-
} catch( Exception ex ) {
-
log.info("Error registering JSP monitoring with jmx " +
-
instance);
-
}
-
}
-
}
-
private synchronized void initServlet(Servlet servlet)throws ServletException {
-
if (instanceInitialized && !singleThreadModel) return;
-
-
try {
-
instanceSupport.fireInstanceEvent(InstanceEvent.BEFORE_INIT_EVENT, servlet);
-
if (Globals.IS_SECURITY_ENABLED) {
-
Object[] args = new Object[] { (facade) };
-
SecurityUtil.doAsPrivilege("init", servlet, classType, args);
-
args = null;
-
} else {
-
servlet.init(facade);
-
}
-
-
instanceInitialized = true;
-
instanceSupport.fireInstanceEvent(InstanceEvent.AFTER_INIT_EVENT, servlet);
-
} catch (UnavailableException f) {
-
-
}
-
}
ʵ¼ÊÉÏÊǵ÷ÓÃÁËservletµÄinit·½·¨£¬ÕâÒѾÊÇservletµÄ´úÂëÁË£¬ÕâÀï²»ÔÙ·ÖÎö¡£
Ç°ÃæÌáµ½µÄservletµÄ¼ÓÔØÖ»ÊDZ»±êʶΪ“load on start”µÄÄÇЩservlet£¬ÄÇôÆäËûservletÊÇÔÚʲôʱºò±»¼ÓÔصÄÄØ£¿Ñ¡ÖÐStandardWrapperµÄinitServlet·½·¨£¬ÔÚeclipseÖв鿴Æäµ÷Óòã´ÎÈçÏ£º
»á·¢ÏÖÓиöallocate·½·¨¼ä½Óµ÷ÓÃÁËËü£¬ÕâÀï¸ø³öÇëÇó½øÈëwrapperÖ®ºóµÄ·½·¨µ÷ÓÃʱÐòͼ£º
¿ÉÒÔ¿´³öÔÚÇëÇó½øÈëwrapperÖ®ºó£¬Í¨¹ýallocate·½·¨´ÓʵÀý³ØÕ»Öе¯³öÒ»¸öservletʵÀýÀ´´¦ÀíÕâ¸öÇëÇó£¬servletʵÀý±»·â×°³ÉfilterChain¶ÔÏ󣬽ô½Ó×Åͨ¹ýһϵÁеĹýÂËÆ÷¹ýÂ˵½´ïservlet.service()·½·¨£¬ÕâÊÇsingleThreadModelģʽµÄ×ö·¨¡£ÔÚ·ÇsingleThreadModelģʽµÄÇé¿öÏÂÊ״μÓÔز¢³õʼʼ»¯servlet¸³¸øinstance×ֶΣ¬Ï´ÎÖ±½Ó´ÓÕâ¸ö×Ö¶ÎÖлñÈ¡servletʵÀý£¬Òò´ËÔÚ·ÇsingleThreadModelģʽÏÂÿ´Î·µ»ØµÄÊÇͬһ¸öservletʵÀý¡£ÓйØsingleThreadModelµÄ¾ßÌå½éÉܲο¼£ºhttp://tomcat.apache.org/tomcat-5.5-doc/servletapi/javax/servlet/SingleThreadModel.html
(ÔðÈα༣ºIT) |