Tomcat源码分析之Bootstrap

Bootstrap

全类名:org.apache.catalina.startup.Bootstrap

执行Bootstrap的main方法进行启动,核心会执行三个方法:

Bootstrap bootstrap = new Bootstrap();
bootstrap.init();
bootstrap.load(args);
bootstrap.start();

bootstrap.init()

该方法会调用initClassLoaders方法,创建3个类加载器

private void initClassLoaders() {
        try {
            commonLoader = createClassLoader("common", null);
            if (commonLoader == null) {
                // no config file, default to this loader - we might be in a 'single' env.
                commonLoader = this.getClass().getClassLoader();
            }
            catalinaLoader = createClassLoader("server", commonLoader);
            sharedLoader = createClassLoader("shared", commonLoader);
        } catch (Throwable t) {
            handleThrowable(t);
            log.error("Class loader creation threw exception", t);
            System.exit(1);
        }
    }

在这里插入图片描述
commonLoader:加载tomcat下的lib目录的jar;
catalinaLoader:用于加载Catalina,Server以及其他组件,父加载器为commonloader;
sharedLoader:是WebappLoader web应用类加载的父类,父加载器为commonloader。

bootstrap.load(args)

调的是catalina.load(args);
catalina对应的类org.apache.catalina.startup.Catalina,然后开始执行catalina的load。

bootstrap.start()

同样调的也是catalina.start(args)。

public void start() throws Exception {
        if (catalinaDaemon == null) {
            init();
        }
				// catalinaDaemon 是在init方法创建,org.apache.catalina.startup.Catalina
        Method method = catalinaDaemon.getClass().getMethod("start", (Class [])null);
        method.invoke(catalinaDaemon, (Object [])null);
    }

执行完start方法,tomcat启动完成

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值