简体   繁体   English

由企业调度程序运行时,Spring Batch CommandLineJobRunner挂起

[英]Spring Batch CommandLineJobRunner hangs when run by enterprise scheduler

Our organization uses the Skybot enterprise scheduler to run batch jobs. 我们的组织使用Skybot企业计划程序来运行批处理作业。 We recently deployed our first spring batch app, and scheduled our jobs to run using CommandLineJobRunner as the main class (Main-Class is defined in the manifest of our jar). 我们最近部署了我们的第一个spring批处理应用程序,并安排了使用CommandLineJobRunner作为主类运行的作业(Main-Class在jar的清单中定义)。 The command looks like this: 该命令如下所示:

java -Dspring.profiles.active=production -jar AppName.jar jobs/jobName.xml jobId

When executed on the command line manually, the jobs run perfectly. 在命令行上手动执行时,作业可以完美运行。 When the same command is executed by the scheduler, the job immediately hangs with no output in the skybot logs, and no work done by the job. 当调度程序执行相同的命令时,该作业立即挂起,并且在skybot日志中没有任何输出,并且该作业没有完成任何工作。 We investigated possible permissions problems, but none exist. 我们调查了可能的权限问题,但不存在。 The spring batch documentation states that CommandLineJobRunner is available for the purpose of running scheduled jobs from the shell, but all our jobs are hanging immediately upon execution. Spring批处理文档指出CommandLineJobRunner可用于从Shell运行计划的作业,但是我们的所有作业在执行后都会立即挂起。 How can we solve this? 我们该如何解决呢?

This appears to be an incompatibility between the CommandLineJobRunner class and Skybot. 这似乎是CommandLineJobRunner类与Skybot之间的不兼容。 After deciding to replace the spring batch class with my own (loading the application context, constructing a JobLauncher, etc), I looked at the source code for CommandLineJobRunner . 在决定用我自己的替换弹簧批处理类(加载应用程序上下文,构造JobLauncher等)之后,我查看了CommandLineJobRunner源代码 The main method has an early call to System.in.available() ; main方法有一个对System.in.available()的早期调用; when we run the job by typing the command and hitting enter, the standard input can read the line feed from the keyboard. 当我们通过键入命令并按Enter键运行作业时,标准输入可以从键盘读取换行符。 Skybot as stdin, on the other hand, does not immediately block, but no line feed follows, so the program waits interminably for input. 另一方面,作为stdin的Skybot不会立即阻止,但不会跟随换行,因此程序会无限等待输入。

From the main method of org.springframework.batch.core.launch.support.CommandLineJobRunner: 从org.springframework.batch.core.launch.support.CommandLineJobRunner的主要方法中:

if (System.in.available() > 0) {
    BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
    String line = " ";
    while (line != null) {
        if (!line.startsWith("#") && StringUtils.hasText(line)) {
            if (logger.isDebugEnabled()) {
                logger.debug("Stdin arg: " + line);
            }
            newargs.add(line);
        }
        line = reader.readLine();
    }
}

Our job parameters are all arguments to the initial command, so this code was unnecessary and problematic. 我们的工作参数都是初始命令的参数,因此此代码是不必要且有问题的。 The solution was to roll our own - very similar to CommandLineJobRunner but without any interaction with the standard input. 解决的办法是自己动手-与CommandLineJobRunner非常相似,但不与标准输入进行任何交互。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM