0

I have a query is that I want my application context to be get refreshed after every 2 minutes..rite now I am getting the application context in my application ..

public class App {
    public static void main(String[] args) {
        ApplicationContext context = new ClassPathXmlApplicationContext(
                "Spring-Module.xml");

        HelloWorld obj = (HelloWorld) context.getBean("helloBean");
        obj.printHello();
    }

Please advise how to refresh the application context in every 2 minutes

4

2 回答 2

2

参考这个链接

http://hsenidians.blogspot.in/2007/07/reloading-spring-context-dynamically.html
http://techdive.in/spring/spring-refresh-application-context

尝试这个

public class RefreshSpringContext {

    public static void main(String args[]) {
        SpringThread t = new SpringThread();
        new Thread(t).start();
    }
}

class SpringThread implements Runnable {

    public SpringThread() {
    }

    public void run() {
        try {
            ApplicationContext context = =  new ClassPathXmlApplicationContext("Spring-Module.xml");
            ((ConfigurableApplicationContext) context).refresh();
            Thread.sleep(12000);

            HelloWorld obj = (HelloWorld) context.getBean("helloBean");
            obj.printHello();
        } catch (Exception e) {
        }
    }
}
于 2012-08-01T05:09:26.060 回答
0

其中一种方法是调用具有睡眠时间的线程。像下面的东西

         for (int i = 0;i < howmanytime;i++) {
            //Pause for 2 seconds
            Thread.sleep(2000);
           //Your logic
        }
于 2012-08-01T04:20:44.057 回答