Job start, stop, abort operation in Spring batch

Source: Internet
Author: User

1, start a job

Running a batch task requires at least two points: a joblauncher and a job to run. They all contain the same or different context. For example, starting a job from the command line will initialize a JVM for each job, so each job will have its own joblauncher, starting the job from the HttpRequest of the Web container, typically using just one joblauncher to start the job asynchronously , the HTTP request invokes the Joblauncher to start the job they need. Examples of web-based job launches:

@Controller  Public class Joblaunchercontroller {    @Autowired    joblauncher joblauncher;    @Autowired    job Job;    @RequestMapping ("/joblauncher.html")    publicvoidthrows  exception{      new  jobparameters ());}    }

2, stop a job

Closing does not happen immediately, because there is no way to force a task to stop immediately, especially when the task is in the developer's own code snippet, and the framework is powerless at the moment, such as a business logic processing. Once control is given back to the frame, it immediately sets the current stepexecution to bachstatus.stopped, meaning to stop, then save, and finally perform the same operation on Jobexecution before completion.

set<long> executions = joboperator.getrunningexecutions ("Samplejob"); Joboperator.stop ( Executions.iterator (). Next ());

3, give up a job

When the execution of a job executes to the failed state, it will be restarted if it is restartable. If the execution process state of a task is abandoned, then the framework does not restart it. The abandoned state also applies to the execution steps so that they can be skipped, even in the event of a restartable task: If a task execution encounters a step marked as abandoned after the last execution failure, the step is skipped directly to the next ( This is determined by the exit code for the task flow definition and execution steps. If the current system process dies ("kill-9" or a system error), the job will not run naturally, but jobrepository cannot detect the error because it has not been notified before the process dies. You have to tell it manually, do you know if the task has failed or consider giving up the task (setting its status to failed or abandoned)-This is the business logic layer that cannot make automatic decisions. You only need to set the failed state in a non-restartable task, or you know that the data is still valid after the reboot. Spring Batch Admin has a series of tools Jobservice to cancel the task that is being performed.

  

Job start, stop, abort operation in Spring batch

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.