天天看點

Java對象this的用法

一般用法, 即為: 匿名内部類對所在目前主類(main class)的調用.

直接上代碼:

(此為RocketMQ NameServer中的代碼片段)

public void start() throws Exception {

    // 初次啟動,這裡會強制執行發送心跳包
    this.registerBrokerAll(true, false, true);

    this.scheduledExecutorService.scheduleAtFixedRate(new Runnable() {
        @Override
        public void run() {
            try {
                BrokerController.this.registerBrokerAll(true, false, brokerConfig.isForceRegister());
            } catch (Throwable e) {
                log.error("registerBrokerAll Exception", e);
            }
        }
    }, 1000 * 10, Math.max(10000, Math.min(brokerConfig.getRegisterNameServerPeriod(), 60000)), TimeUnit.MILLISECONDS);
}
           

filename: 

org.apache.rocketmq.broker.BrokerController#start:

作用:

Broker在核心控制器啟動時,會強制發送一次心跳包,接着建立一個定時任務,定時向路由中心發送心跳包。