无法重新启动Spring批处理作业 [英] Unable to restart a Spring batch job

查看:760
本文介绍了无法重新启动Spring批处理作业的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Spring Batch作业,可以读取,转换和写入Oracle数据库.我正在通过CommandLineJobRunner实用程序运行该作业(使用胖子+通过Maven Shade插件生成的依赖项);该作业随后由于达到Java堆内存限制"而中途失败,并且该作业未标记为FAILED,而是仍然显示STARTED状态.

I have a spring batch job which reads, transforms and writes to an Oracle database. I am running the job via the CommandLineJobRunner utility (using a fat jar + dependencies generated with the maven shade plugin); the job subsequently fails halfway through due to "java heap memory limit reached" and the job is not marked as FAILED but rather still shows status STARTED.

我尝试使用相同的作业参数(如文档所示)重新运行该作业,但这给了我这个错误:

I tried to re-run the job using the same job parameters (as the docs suggest) but this gives me this error:

5:24:34.147 [main] ERROR o.s.b.c.l.s.CommandLineJobRunner - Job Terminated in error: A job execution for this job is already running: JobInstance: id=1, version=0, Job=[maskTableJob]

org.springframework.batch.core.repository.JobExecutionAlreadyRunningException:该作业的作业执行已在运行:JobInstance:id = 1,version = 0,Job = [maskTableJob] 在org.springframework.batch.core.repository.support.SimpleJobRepository.createJobExecution(SimpleJobRepository.java:120)〜[maskng-batch-1.0-SNAPSHOT-executable.jar:1.0-SNAPSH

org.springframework.batch.core.repository.JobExecutionAlreadyRunningException: A job execution for this job is already running: JobInstance: id=1, version=0, Job=[maskTableJob] at org.springframework.batch.core.repository.support.SimpleJobRepository.createJobExecution(SimpleJobRepository.java:120) ~[maskng-batch-1.0-SNAPSHOT-executable.jar:1.0-SNAPSH

我尝试了各种方法(例如使用-restart参数将状态手动设置为FAILED),但无济于事.我在这里缺少什么,因为我认为春季批处理的优点之一是它可以重新启动从...开始停工的工作……!!?

I have tried all sorts of things (like manually setting the status to FAILED, using the -restart argument) but to no avail. Is there something I am missing here as I thought one of the strong points of spring batch is its ability to restart jobs where they left off....!!?

推荐答案

您应该知道的第一件事是Joblauncher不能用于重新启动已经运行的作业. 之所以收到"JobExecutionAlreadyRunningException",是因为要传递的参数已经存在于数据库中,因此您将收到此异常.

First thing that you should know is Joblauncher cannot be used to restart the job which has already run . The reason why you are getting "JobExecutionAlreadyRunningException" is because the parameter that you are passing is already present in the DB and hence you are getting this exception .

在春季批处理中,如果作业以"FAILED"或"STOPPED"状态完成,则可以重新启动.

In spring batch , job can be restarted if it has completed with "FAILED" status or "STOPPED" status.

JobOperator 具有重新启动方法,该方法可通过传递以"FAILED"或"STOPPED"状态完成的作业执行ID来重新启动失败的作业.

JobOperator has restart method which can be used to restart a failed job by passing the jobexecution id which was completed with "FAILED" status or "STOPPED" status.

请注意,如果作业以完成"状态完成,则无法重新启动. 在这种情况下,您将必须提交具有新工作参数的新工作

Please note that a job cannot be restarted if it has completed with "FINISHED" status . In this case you will have to submit new job with new job parameters

如果要手动将作业状态设置为失败,请运行以下查询并使用JobOperator.restart()方法重新启动作业.

If you want to manually set the status of job as failed then run the below query and restart the job using JobOperator.restart() method.

update batch_job_execution set status="FAILED", version=version+1 where job_instance_id=jobId;

不正确的事务管理处理可能是您的工作状态未更新为"FAILED"状态的可能原因之一.即使作业遇到运行时异常,也请确保您正在完成事务.

Improper handling of transaction management could be one possible reason why your job status is not getting updated with the "FAILED" status . Please make sure you are transaction is getting completed even if the job has encountered run time exception.

这篇关于无法重新启动Spring批处理作业的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆