首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 软件管理 > 软件架构设计 >

记要之spring

2012-10-21 
记录之spring如果要在spring所有bean装载完成之后调用某段代码时,可以让一个bean实现接口:org.springframe

记录之spring

如果要在spring所有bean装载完成之后调用某段代码时,可以让一个bean实现接口:

org.springframework.context.ApplicationListene

然后实现他的

public void onApplicationEvent(ApplicationEvent event) 

?方法

官方文档说:

?那么每当一个public void onApplicationEvent(ApplicationEvent event) {if(event instanceof ContextRefreshedEvent){Runnable t = new Runnable() {@Overridepublic void run() {long starttime = System.currentTimeMillis();dispenseFeed.despense();while (true) {long curtime = System.currentTimeMillis();if (curtime - starttime > 20000) {System.out.println("分发开始");dispenseFeed.despense();starttime = curtime;try {Thread.sleep(1000);} catch (InterruptedException e) {e.printStackTrace();}}}}};Thread runnablet=new Thread(t);runnablet.start();System.out.println("线程起动");}}?