java基础-tomcat启动过程

本文详细解析了Tomcat服务器从main方法开始到服务完全启动的全过程,包括各个组件和服务的初始化及启动顺序。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Bootstrap,启动main方法
public static void main(String args[]) {
private void load(String[] arguments){
    会启动Catalina中的
    public void load() {
        ...
        // 初始化 并加载 解析server.xml文件
        initDirs();
        initNaming();
        Digester digester = createStartDigester();
       
        digester.push(this);
        digester.parse(inputSource);

        getServer().init(); // 会执行StandardServer中的protected void initInternal()

    }
public void start(){
    会启动Catalina中的
    public void start() {
        ...
        getServer().start();// 会执行StandardServer中的protected void startInternal()

    }

StandardServer  包含StandstardService
synchronized (services) {
    for (int i = 0; i < services.length; i++) {
        services[i].start();
    }
}

StandstardService  包含StandstardEngine
if (container != null) {
     synchronized (container) {
          container.start();
     }
}

StandstardEngine,包含ContainerBase中的
protected synchronized void startInternal() throws LifecycleException {
protected void threadStart() {
这时候会启动一个后台线程

 
接着会启动Connector中的
protected void startInternal() throws LifecycleException {
接着会启动AbstractProtocol中的
public void start() throws Exception {
接着会启动AbstractEndpoint中的
public final void start() throws Exception {
接着会启动JIoEndpoint中的
public void startInternal() throws Exception {
这时候会启动两个线程,一个监听请求的,一个异步化操作的。

 
接着会启动MapperListener中的
public void startInternal() throws LifecycleException {

至此服务全部启动完毕。
2013-9-6 10:23:06 org.apache.catalina.startup.Catalina start
信息: Server startup in 200533 ms

整个过程有点像剥洋葱,一层一层嵌套启动,非常经典的一个过程。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值