028-86922220

建站动态

根据您的个性需求进行定制 先人一步 抢占小程序红利时代

如何使用prepareRefresh()

这篇文章主要介绍“如何使用prepareRefresh()”,在日常操作中,相信很多人在如何使用prepareRefresh()问题上存在疑惑,小编查阅了各式资料,整理出简单好用的操作方法,希望对大家解答”如何使用prepareRefresh()”的疑惑有所帮助!接下来,请跟着小编一起来学习吧!

创新互联长期为成百上千家客户提供的网站建设服务,团队从业经验10年,关注不同地域、不同群体,并针对不同对象提供差异化的产品和服务;打造开放共赢平台,与合作伙伴共同营造健康的互联网生态环境。为南沙企业提供专业的网站建设、成都网站设计,南沙网站改版等技术服务。拥有10余年丰富建站经验和众多成功案例,为您定制开发。

refresh()

这个方法主要做了一下这几件事情:

这里我们先来看看容器刷新前做了些什么吧

prepareRefresh()

方法的源码并不多,如下:

protected void prepareRefresh() {
	// Switch to active.
	// 这一句很明显的获取了系统当前时间,其实他的作用是来记录当前的启动时间的
	this.startupDate = System.currentTimeMillis();
	
	// 这两个状态的设置,前者关闭程序设置为false,后者运行标识设置为true
	this.closed.set(false);
	this.active.set(true);

	if (logger.isDebugEnabled()) {
		if (logger.isTraceEnabled()) {
			logger.trace("Refreshing " + this);
		}
		else {
			logger.debug("Refreshing " + getDisplayName());
		}
	}

	// Initialize any placeholder property sources in the context environment.
	// 目前还是一个空方法,应该后面会补充
	initPropertySources();

	// Validate that all properties marked as required are resolvable:
	// see ConfigurablePropertyResolver#setRequiredProperties
	// 校验 xml配置文件
	getEnvironment().validateRequiredProperties();

	// Store pre-refresh ApplicationListeners...
	// 判断刷新前的运用程序监听集合是否为空,为空初始化applicationListeners监听,不为空,则清空监听器
	if (this.earlyApplicationListeners == null) {
		this.earlyApplicationListeners = new LinkedHashSet<>(this.applicationListeners);
	}
	else {
		// Reset local application listeners to pre-refresh state.
		this.applicationListeners.clear();
		this.applicationListeners.addAll(this.earlyApplicationListeners);
	}

	// Allow for the collection of early ApplicationEvents,
	// to be published once the multicaster is available...
	// 创建刷新前的事件集合
	this.earlyApplicationEvents = new LinkedHashSet<>();
}

这个方法prepareRefresh(),是在spring5.3之后加了程序,所以之前的版本是没有办法看到的。

就做了这几件事情

到此,关于“如何使用prepareRefresh()”的学习就结束了,希望能够解决大家的疑惑。理论与实践的搭配能更好的帮助大家学习,快去试试吧!若想继续学习更多相关知识,请继续关注创新互联网站,小编会继续努力为大家带来更多实用的文章!


本文名称:如何使用prepareRefresh()
文章源于:http://www.tsicrk.com/article/gsochp.html

其他资讯

让你的专属顾问为你服务

2.4443s