27 lines
3.2 KiB
HTML
27 lines
3.2 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>Configuring a JobLauncher</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="ch04s03.xhtml" title="Configuring a JobRepository"/><link rel="next" href="ch04s05.xhtml" title="Running a Job"/></head><body><header/><section class="section" title="Configuring a JobLauncher" epub:type="subchapter" id="configuringJobLauncher"><div class="titlepage"><div><div><h2 class="title" style="clear: both">Configuring a JobLauncher</h2></div></div></div><p>The most basic implementation of the
|
|
<code class="classname">JobLauncher</code> interface is the
|
|
<code class="classname">SimpleJobLauncher</code>. Its only required dependency is
|
|
a <code class="classname">JobRepository</code>, in order to obtain an
|
|
execution:</p><pre class="programlisting"><bean id="jobLauncher"
|
|
class="org.springframework.batch.core.launch.support.SimpleJobLauncher">
|
|
<property name="jobRepository" ref="jobRepository" />
|
|
</bean></pre><p>Once a <a class="link" href="ch03.xhtml#jobExecution"><code class="classname">JobExecution</code></a> is
|
|
obtained, it is passed to the execute method of
|
|
<code class="classname">Job</code>, ultimately returning the
|
|
<code class="classname">JobExecution</code> to the caller:</p><div style="text-align: center; " class="mediaobject"><img style="text-align: middle; " src="images/job-launcher-sequence-sync.png" width="486"/></div><p>The sequence is straightforward and works well when launched from a
|
|
scheduler. However, issues arise when trying to launch from an HTTP
|
|
request. In this scenario, the launching needs to be done asynchronously
|
|
so that the <code class="classname">SimpleJobLauncher</code> returns immediately
|
|
to its caller. This is because it is not good practice to keep an HTTP
|
|
request open for the amount of time needed by long running processes such
|
|
as batch. An example sequence is below:</p><div style="text-align: center; " class="mediaobject"><img style="text-align: middle; " src="images/job-launcher-sequence-async.png" width="486"/></div><p>The <code class="classname">SimpleJobLauncher</code> can easily be
|
|
configured to allow for this scenario by configuring a
|
|
<code class="classname">TaskExecutor</code>:</p><pre class="programlisting"><bean id="jobLauncher"
|
|
class="org.springframework.batch.core.launch.support.SimpleJobLauncher">
|
|
<property name="jobRepository" ref="jobRepository" />
|
|
<property name="taskExecutor">
|
|
<bean class="org.springframework.core.task.SimpleAsyncTaskExecutor" />
|
|
</property>
|
|
</bean></pre><p>Any implementation of the spring <code class="classname">TaskExecutor</code>
|
|
interface can be used to control how jobs are asynchronously
|
|
executed.</p></section><footer/></body></html> |