Files
spring-batch/build/reference-epub-work/ch12s06.xhtml
Michael Minella 75ab909314 update
2017-03-23 10:18:33 -05:00

23 lines
3.9 KiB
HTML

<?xml version="1.0" encoding="UTF-8" standalone="no"?><!DOCTYPE html><html xmlns="http://www.w3.org/1999/xhtml" xmlns:epub="http://www.idpf.org/2007/ops" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:pls="http://www.w3.org/2005/01/pronunciation-lexicon" xmlns:ssml="http://www.w3.org/2001/10/synthesis" xmlns:svg="http://www.w3.org/2000/svg"><head><title>Running a job</title><link rel="stylesheet" type="text/css" href="docbook-epub.css"/><meta name="generator" content="DocBook XSL Stylesheets V1.78.1"/><link rel="prev" href="ch12s05.xhtml" title="Processing Models"/><link rel="next" href="ch12s07.xhtml" title="Contexts"/></head><body><header/><section class="section" title="Running a job" epub:type="subchapter" id="jsrRunningAJob"><div class="titlepage"><div><div><h2 class="title" style="clear: both">Running a job</h2></div></div></div><p>The entrance to executing a JSR-352 based job is through the
<code class="classname">javax.batch.operations.JobOperator</code>. Spring Batch provides our own implementation to
this interface (<code class="classname">org.springframework.batch.core.jsr.launch.JsrJobOperator</code>). This
implementation is loaded via the <code class="classname">javax.batch.runtime.BatchRuntime</code>. Launching a
JSR-352 based batch job is implemented as follows:</p><pre class="programlisting">
JobOperator jobOperator = BatchRuntime.getJobOperator();
long jobExecutionId = jobOperator.start("fooJob", new Properties());
</pre><p>The above code does the following:</p><p>
</p><div class="itemizedlist" epub:type="list"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem" epub:type="list-item"><p>Bootstraps a base ApplicationContext - In order to provide batch functionality, the framework
needs some infrastructure bootstrapped. This occurs once per JVM. The components that are
bootstrapped are similar to those provided by <code class="classname">@EnableBatchProcessing</code>.
Specific details can be found in the javadoc for the <code class="classname">JsrJobOperator</code>.
</p></li><li class="listitem" epub:type="list-item"><p>Loads an <code class="classname">ApplicationContext</code> for the job requested - In the example
above, the framework will look in /META-INF/batch-jobs for a file named fooJob.xml and load a
context that is a child of the shared context mentioned previously.</p></li><li class="listitem" epub:type="list-item"><p>Launch the job - The job defined within the context will be executed asynchronously. The
<code class="classname">JobExecution</code>'s id will be returned.</p></li></ul></div><p>
</p><div class="note" title="Note" epub:type="notice"><table style="border: 0; "><tr><td style="text-align: center; vertical-align: top; width: 25; " rowspan="2"><img alt="[Note]" src="images/note.png"/></td><th style="text-align: left; ">Note</th></tr><tr><td style="text-align: left; vertical-align: top; "><p>All JSR-352 based batch jobs are executed asynchronously.</p></td></tr></table></div><p>When <code class="classname">JobOperator#start</code> is called using <code class="classname">SimpleJobOperator</code>,
Spring Batch determines if the call is an initial run or a retry of a previously executed run. Using the
JSR-352 based <code class="classname">JobOpeator#start(String jobXMLName, Properties jobParameters)</code>, the
framework will always create a new <code class="classname">JobInstance</code> (JSR-352 job parameters are
non-identifying). In order to restart a job, a call to
<code class="classname">JobOperator#restart(long executionId, Properties restartParameters)</code> is required.
</p></section><footer/></body></html>