Spring batch ApplicationContext

问题描述 投票:0回答:1

我在我的项目中使用Spring Batch应用程序。一旦启动spring batch main方法,在main方法的末尾,我就用来关闭classpathxmlapplicationcontext。

  1. 是否有必要关闭classpathxmlapplicationcontext?
  2. 一个主要问题是,如果我在批处理应用程序之间触发了任何异步调用,那么当主方法代码到达classpathxmlapplicationcontext.close()时,那些异步调用将被终止。
  3. 如果我注释了classpathxmlapplicationcontext.close()然后,即使所有逻辑都已完成,我的程序仍在连续运行而没有任何终止。
  4. 如何解决?我需要在关闭classpathxmlapplicationcontext之前执行所有异步调用。
  5. 考虑我所有的异步都会花费一点多余的时间。
java asynchronous spring-batch applicationcontext
1个回答
0
投票

是,我们必须关闭classpathxmlapplicationcontext。

尝试下面的代码

ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(...);
try {
    [...]
} finally {
    ctx.close();
}

或者,在Java 7或更高版本中

try(ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(...)) {
    [...]
}
© www.soinside.com 2019 - 2024. All rights reserved.