读书人

记要之spring

发布时间: 2012-10-21 09:00:07 作者: rapoo

记录之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("线程起动");}}?

读书人网 >软件架构设计

热点推荐