tomcat的reload原理

来源:互联网 发布:淘宝商城帐篷 编辑:程序博客网 时间:2024/06/10 01:05

这里写图片描述

整个处理流程是在一个定时任务ContainerBackgroundProcessor线程进行处理的

/**     * Private thread class to invoke the backgroundProcess method      * of this container and its children after a fixed delay.     */    protected class ContainerBackgroundProcessor implements Runnable {        @Override        public void run() {            while (!threadDone) {                try {                    Thread.sleep(backgroundProcessorDelay * 1000L);                } catch (InterruptedException e) {                    // Ignore                }                if (!threadDone) {                    Container parent = (Container) getMappingObject();                    ClassLoader cl =                         Thread.currentThread().getContextClassLoader();                    if (parent.getLoader() != null) {                        cl = parent.getLoader().getClassLoader();                    }                    processChildren(parent, cl);                }            }        }        protected void processChildren(Container container, ClassLoader cl) {            try {                if (container.getLoader() != null) {                    Thread.currentThread().setContextClassLoader                        (container.getLoader().getClassLoader());                }                container.backgroundProcess();            } catch (Throwable t) {                ExceptionUtils.handleThrowable(t);                log.error("Exception invoking periodic operation: ", t);            } finally {                Thread.currentThread().setContextClassLoader(cl);            }            Container[] children = container.findChildren();            for (int i = 0; i < children.length; i++) {                if (children[i].getBackgroundProcessorDelay() <= 0) {                    processChildren(children[i], cl);                }            }        }    }

最终一步步地调用StandardContext的reload()方法进行重新加载.

0 0