zoukankan      html  css  js  c++  java
  • dubbo源码分析10——服务暴露1_export()方法分析

    ServiceConfig类中的export()方法,是dubbo服务暴露的入口方法,被触发的时机有两个:

        1. spring容器初始化完成所有的bean实例后,通过事件机制触发

        2. 实现InitializingBean的方法中进行触发

    export()方法源码如下:

    public synchronized void export() {
            if (provider != null) {
                if (export == null) {
                    export = provider.getExport();
                }
                if (delay == null) {
                    delay = provider.getDelay();
                }
            }
            if (export != null && ! export.booleanValue()) {
                return;
            }
            if (delay != null && delay > 0) {    //如果要进行延迟暴露,则开启一个子线程,在子线程中进行服务暴露的工作
                Thread thread = new Thread(new Runnable() {
                    public void run() {
                        try {
                            Thread.sleep(delay);
                        } catch (Throwable e) {
                        }
                        doExport();
                    }
                });
                thread.setDaemon(true);  //由于是后台线程,则如果当前只有后台线程存在的情况下,JAVA虚拟机将退出,这样当主线程结束,以及主线程的其他user线程都结束的情况下,daemon线程也将结束
                thread.setName("DelayExportServiceThread");
                thread.start();
            } else {
                doExport(); 
            }
        }
        

    通过查看源码可知,export方法处理了如何延时暴露,然后调用doExport()方法进行暴露

  • 相关阅读:
    vue 路由的实现 hash模式 和 history模式
    标准规范
    知识产权、项目收尾
    合同法、著作权、实施条例
    招投标法、政府采购法
    项目成熟度模型、量化项目管理
    信息系统综合测试与管理
    信息系统安全管理
    Spring Boot 6. 与数据访问
    Spring Boot 5. 与Docker
  • 原文地址:https://www.cnblogs.com/hzhuxin/p/7675796.html
Copyright © 2011-2022 走看看