
设计模式
文章平均质量分 68
tanglihai
这是一个JAVA开发者
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
Spring在监听器中用到的适配器模式
广播器AbstractApplicationEventMulticaster 的方法retrieveApplicationListeners获取监听器时,会通过supportsEvent(listener, eventType, sourceType)方法筛选出支持相应事件类型的监听器,如下。 protected boolean supportsEvent(ApplicationListener<?> listener, ResolvableType eventType, Class<原创 2021-12-29 20:45:00 · 479 阅读 · 0 评论 -
Spring-Boot和Spring的监听器模式
最近阅读SpringBoot的源码,发现一个奇怪的现象,项目中有两处地方具有发布事件功能,一个是SpringApplicationRunListener接口;另一个是ApplicationEventPublisher接口的publishEvent方法,ApplicationContext接口实现了该接口。先讲结论。经过仔细分析,发现SpringApplicationRunListener接口是属于SpringBoot包下的,该接口用于发布SpringBoot相关流程的事件;而ApplicationE原创 2021-12-22 21:01:26 · 639 阅读 · 0 评论 -
Tomcat8中LifecycleBase使用到的模版方法模式和监听器模式
下面是Tomcat中Lifecycle接口相关的类图,本文讲解使用到了Lifecycle和LifecycleBase类。Lifecycle处于最顶端的位置,用于对Tomcat所有的组件进行生命周期管理,在这里我们先不讨论和本文无关的Container接口以及MBeanRegistration、JmxEnabled接口,而LifecycleMBeanBase是用于JMX进行管理而设计的类,也不在...原创 2018-12-07 23:25:31 · 1317 阅读 · 1 评论 -
单例的几种写法优劣势对比(双重同步锁、饿汉、静态内部类)
一、线程安全的双重检查懒加载单例public class Singleton { private volatile static Singleton singleton; private Singleton(){} public static Singleton getInstance(){ if (singleton == null){ ...原创 2019-07-10 19:00:59 · 1531 阅读 · 0 评论