Nacos深入浅出(七)
2024-09-02 07:35:20
大家可以把这个也下载下来,结合之前的Nacos一起来看下,感觉前面几篇看了好像冰山一角的感觉
学无止境!
https://github.com/nacos-group/nacos-spring-project
其实前面的很多猜测都是在这个里面去实现的;这个明天再系统的去看吧;
把之前的问题给大家补上,就是EventDispatcher.java如何初始化的
static final CopyOnWriteArrayList<Entry> LISTENER_HUB = new CopyOnWriteArrayList<Entry>();
这里给大家看下一个小方法,我自己写的
public abstract class AbstractEventListener {
// 抽象类中定义一个构造方法
public AbstractEventListener(){
System.out.println("print abstract constractor init");
} static class AsyncNotifyService extends AbstractEventListener{
private String serviceName ;
// 子类中自定义构造函数
public AsyncNotifyService(String serviceName){
System.out.println("print class AsyncNotifyService constractor init");
this.serviceName = serviceName;
}
}
// 子类中在自定义构造函数
static class LongPollingService extends AbstractEventListener {
public LongPollingService() {
System.out.println("print class LongPollingService constractor init");
}
} public static void main(String[] args){
AsyncNotifyService asyncNotifyService = new AsyncNotifyService("123");
LongPollingService longPollingService = new LongPollingService();
}
}
其实这个不管父类是抽象类还是具体某个类,子类在继承的时候都会先调用父类中的构造函数,然后再执行子类中的构造函数;
下面贴下结果:
这样再回去看Nacos的方法就能明白了
public class LongPollingService extends AbstractEventListener {}
public class AsyncNotifyService extends AbstractEventListener {} 在每个子类的Service中,都有构造函数,在构造函数中进行了初始化,初始化了LISTENER_HUB ;
这样就完成了; 明天继续给大家写!
最新文章
- 【hive】——Hive基本操作
- iOS - SQLite 数据库存储
- C++ 引用
- Python基础4- 字符串
- 高性能MySQL --- 读书笔记(1) - 2016/8/2
- 在MVC中如何愉快使用Ajax
- LinqToXML~读XML文件续
- 开源欣赏wordpress之用户新增user-new.php
- Unable to open connection to supplicant on ";/data/misc/wifi/sockets/wlan0";
- Java实现CORS跨域请求
- MySQL执行一个查询的过程
- 2.关于QT中的Dialog(模态窗口),文件选择器,颜色选择器,字体选择器,消息提示窗口
- STM32F0使用LL库实现MS5536C通讯
- sqlserver开窗函数在财务对账中的用法
- Python之多线程和多进程
- JS中的跨域问题
- codeforces510B
- RedHat如何关闭防火墙&#160;:&#160;http://blog.csdn.net/chongxin1/article/details/76072758
- Android开发——Android多进程以及使用场景介绍
- vue中assets和static的区别
热门文章
- nodejs中的子进程,深入解析child_process模块和cluster模块
- Linux系统资源查看与设置
- Ubuntu 更新/安装nodejs
- Collaborative Index Embedding for Image Retrieval
- [acm]HDOJ 2673 shǎ崽 OrOrOrOrz
- WPF TreeView 后台C#选中指定的Item, 需要遍历
- TI官网常用链接
- ActiveRecord 的类型初始值设定项引发异常
- deleteMany is not a function
- JavaScript高级程序设计学习笔记第三章--基本概念