如何关闭ApplicationContext?

时间:2019-07-15 08:23:42

标签: java spring

我有Spring Web应用程序,需要在运行时重新加载新的application.properties。对我来说,完成当前所有任务很重要。我的代码是:

public void restartSpringApplication() {
    ApplicationArguments args = applicationContext.getBean(ApplicationArguments.class);
    Thread thread = new Thread(() -> {
        applicationContext.close();
        applicationContext = SpringApplication.run(springBootClassHolder.getClazz(), args.getSourceArgs());
    });

    thread.setDaemon(false);
    thread.start();
}

此代码安全吗?如果正在进行某笔交易,那么它会等到交易完成或杀死交易吗?

0 个答案:

没有答案