如何写大盘昨日的指数:如REF("SZ8110zx2390011$CLOSE",1)怎么不对?

锁定老帖子
该帖已经被评为新手帖
发表时间:&&
自己写了个简单的测试程序,加了个close()方法,以测试是在何时调用这个方法的,结果发现无论如何触发,这个方法是都无法被调用的,除非加上这句话:
factory.destroySingletons(); 大概看了源代码,主要是把Singleton对象从HashSet中remove(),并且调用对应的close()方法,然后我又查了Without EJB,在使用连接池的时候使用了destroy-method="close",并且发现了这句话:
Note that the myDataSource definition specifies a destroy-method: The bean factory will automatically
invoke the close() method of BasicDataSource on shutdown.
就是说这个方法是在on shutdown的时候容器自动调用的,那么shutdown应该如何理解呢?我现在的疑问是,这个方法是怎么触发的呢?因为我自己在测试的时候无论怎样都触发不了这个方法,除非调用factory.destroySingletons();?
想了好久,不甚理解呀,郁闷!
来自: 浙江宁波
发表时间:&&
AbstractApplicationContext.Close
请登录后投票
等级: 资深会员
文章: 4925
积分: 2991
来自: 北京
发表时间:&&
singleton="false"试试
请登录后投票
发表时间:&&
gigix 写道singleton="false"试试
factory.destroySingletons();这里面的代码只是remove() Singletons,remove后会触发destroy-method="close",如果连Singleton都不是,那就更不可能会触发destroy-method="close"了,而且我试过了,确实不行
请登录后投票
发表时间:&&
jjx 写道AbstractApplicationContext.Close
如果可以通过这个方法来触发的话,那么BeanFactory又没有这个方法,那如何触发呢? 而且,你如何保证容器会调用AbstractApplicationContext.Close这个方法呢?
我对文档上说的自动调用甚是不解,如何个自动法呢?
请登录后投票
发表时间:&&
举个例子,ContextLoaderListener的源代码,
我们知道,如果要在tomcat里面使用spring的话需要这个Listener(或者ContextLoaderServlet)
public class ContextLoaderListener implements ServletContextListener {
private ContextLoader contextL
* Initialize the root web application context.
public void contextInitialized(ServletContextEvent event); {
this.contextLoader = createContextLoader();;
this.contextLoader.initWebApplicationContext(event.getServletContext(););;
* Create the ContextLoader to use. Can be overridden in subclasses.
* @return the new ContextLoader
protected ContextLoader createContextLoader(); {
return new ContextLoader();;
* Return the ContextLoader used by this listener.
public ContextLoader getContextLoader(); {
return contextL
* Close the root web application context.
public void contextDestroyed(ServletContextEvent event); {
this.contextLoader.closeWebApplicationContext(event.getServletContext(););;
当tomcat关闭的时候会自动调用contextDestroyed(ServletContextEvent event)这个方法。在看一下contextLoader的closeWebApplicationContext方法:
public void closeWebApplicationContext(ServletContext servletContext); throws ApplicationContextException {
servletContext.log("Closing root WebApplicationContext");;
Object wac = servletContext.getAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE);;
if (wac instanceof ConfigurableApplicationContext); {
((ConfigurableApplicationContext); wac);.close();;
就应该明白文档里面是什么意思了,AbstractApplicationContext.Close这个方法是要你自己调用的,在程序要结束的时候保证调用这个close方法,在这里的话就是由Listener来保证tomcat退出的时候调用close方法。
AbstractApplicationContext.Close的代码
public void close(); {
("Closing application context [" + getDisplayName(); + "]");;
// Destroy all cached singletons in this context,
// invoking DisposableBean.destroy and/or "destroy-method".
getBeanFactory();.destroySingletons();;
// publish corresponding event
publishEvent(new ContextClosedEvent(this););;
}
其实就是调用context里面的beanFactory的destroySingletons()方法了,这个没什么好说的。我的意思就是,容器本身不知道什么时候要shutdown了,这个消息是要靠外部(程序员)来提供的。
PS:偶说的容器是指ApplicationContext,不知道你说的容器是不是tomcat之类的web container,MS说法有点不统一,呵呵。
请登录后投票
发表时间:&&
明白了,谢谢啊! 嘎嘎
请登录后投票
等级: 初级会员
来自: 成都
发表时间:&&
我怎么没有看到factory.destroySingletons()方法呢?
请登录后投票
来自: 上海
发表时间:&&
spring-src in eclipsedestroy-methodright clickreferenceproject
请登录后投票
跳转论坛:移动开发技术
Web前端技术
Java企业应用
编程语言技术

我要回帖

更多关于 ora 39001 的文章

 

随机推荐