我知道这已被问过,但我仍然无法找到我的问题的确切答案。我的问题是这样的:我使用spring批处理将数据导出到SOLR搜索服务器。它需要每分钟运行一次,所以我可以导出所有更新。第一次执行通过OK,但与第二个抱怨:
2014-10-02 20:37:00,022 [defaultTaskScheduler-1] ERROR: catching
org.springframework.batch.core.repository.JobInstanceAlreadyCompleteException: A job instance already exists and is complete for parameters={catalogVersionPK=3378876823725152,
type=UPDATE}. If you want to run this job again, change the parameters.
at org.springframework.batch.core.repository.support.SimpleJobRepository.createJobExecution(SimpleJobRepository.java:126)
at
我当然可以是一个日期 - 时间参数添加到作业是这样的:
.addLong("time", System.getCurrentTimeMillis())
,然后运行作业不止一次。不过,我也想查询作业的最后执行,让我有这样的代码:
DateTime endTime = new DateTime(0);
JobExecution je = jobRepository.getLastJobExecution("searchExportJob", new JobParametersBuilder().addLong("catalogVersionPK", catalogVersionPK).addString("type", type).toJobParameters());
if (je != null && je.getEndTime() != null) {
endTime = new DateTime(je.getEndTime());
}
,这没有返回,因为我没有提供时间参数。所以好像我可以运行一次这个工作并获得最后的执行时间,或者我可以多次运行它,而不是最后的执行时间。我真的坚持:(
我可以'因为那时候执行是失败的。如果我没有想到更好的方法,我可能会最终使用您的解决方案2-创建一个自定义的DAO。 – 2014-10-06 14:05:54
@PetarTahchiev让我知道如果工作正常。为了解决这个问题:) – Xstian 2014-10-06 19:11:03