Spring batch pause/resume vs stop/restart

假装没事ソ 提交于 2019-12-08 05:13:01

问题


I am new to spring batch and has some questions regarding pause/resume. After reading spring batch documentation, there doesn't seem to have any built-in pause or resume functions. However, there is this use case i found from the main site:

http://docs.spring.io/spring-batch/2.0.x/cases/pause.html

There are no sample codes provided or is there any place I could find these samples?

In Spring batch, I understand there is a stop and restart function built-in. Could I use this as a form of pause and resume? Or there is another better way of doing it?


回答1:


Stop/restart is essentially pause and resume. It allows you to programmatically stop a running job and pick up where it left off.




回答2:


use job operator for this, it is the basic interface which provides functionalities such as stop , restart , getStatus

public interface JobOperator {

List<Long> getExecutions(long instanceId) throws NoSuchJobInstanceException;

List<Long> getJobInstances(String jobName, int start, int count)
      throws NoSuchJobException;

Set<Long> getRunningExecutions(String jobName) throws NoSuchJobException;

String getParameters(long executionId) throws NoSuchJobExecutionException;

Long start(String jobName, String parameters)
      throws NoSuchJobException, JobInstanceAlreadyExistsException;

Long restart(long executionId)
      throws JobInstanceAlreadyCompleteException, NoSuchJobExecutionException,
              NoSuchJobException, JobRestartException;

Long startNextInstance(String jobName)
      throws NoSuchJobException, JobParametersNotFoundException, JobRestartException,
             JobExecutionAlreadyRunningException, JobInstanceAlreadyCompleteException;

boolean stop(long executionId)
      throws NoSuchJobExecutionException, JobExecutionNotRunningException;

String getSummary(long executionId) throws NoSuchJobExecutionException;

Map<Long, String> getStepExecutionSummaries(long executionId)
      throws NoSuchJobExecutionException;

Set<String> getJobNames();

}

Here is an example for that

JOB_OPERATOR



来源:https://stackoverflow.com/questions/18961698/spring-batch-pause-resume-vs-stop-restart

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!