public class SimpleJobLauncher extends java.lang.Object implements JobLauncher, org.springframework.beans.factory.InitializingBean
JobLauncher
interface. The Spring Core
TaskExecutor
interface is used to launch a Job
. This means
that the type of executor set is very important. If a
SyncTaskExecutor
is used, then the job will be processed
within the same thread that called the launcher. Care should
be taken to ensure any users of this class understand fully whether or not
the implementation of TaskExecutor used will start tasks synchronously or
asynchronously. The default setting uses a synchronous task executor.
There is only one required dependency of this Launcher, a
JobRepository
. The JobRepository is used to obtain a valid
JobExecution. The Repository must be used because the provided Job
could be a restart of an existing JobInstance
, and only the
Repository can reliably recreate it.JobRepository
,
TaskExecutor
Modifier and Type | Field and Description |
---|---|
protected static org.apache.commons.logging.Log |
logger |
Constructor and Description |
---|
SimpleJobLauncher() |
Modifier and Type | Method and Description |
---|---|
void |
afterPropertiesSet()
Ensure the required dependencies of a
JobRepository have been
set. |
JobExecution |
run(Job job,
JobParameters jobParameters)
Run the provided job with the given
JobParameters . |
void |
setJobRepository(JobRepository jobRepository)
Set the JobRepository.
|
void |
setTaskExecutor(org.springframework.core.task.TaskExecutor taskExecutor)
Set the TaskExecutor.
|
public JobExecution run(Job job, JobParameters jobParameters) throws JobExecutionAlreadyRunningException, JobRestartException, JobInstanceAlreadyCompleteException, JobParametersInvalidException
JobParameters
. The
JobParameters
will be used to determine if this is an execution
of an existing job instance, or if a new one should be created.run
in interface JobLauncher
job
- the job to be run.jobParameters
- the JobParameters
for this particular
execution.JobExecution
if it returns synchronously. If the
implementation is asynchronous, the status might well be unknown.JobExecutionAlreadyRunningException
- if the JobInstance already
exists and has an execution already running.JobRestartException
- if the execution would be a re-start, but a
re-start is either not allowed or not needed.JobInstanceAlreadyCompleteException
- if this instance has already
completed successfullyJobParametersInvalidException
- thrown if jobParameters is invalid.public void setJobRepository(JobRepository jobRepository)
jobRepository
- instance of JobRepository
.public void setTaskExecutor(org.springframework.core.task.TaskExecutor taskExecutor)
taskExecutor
- instance of TaskExecutor
.public void afterPropertiesSet() throws java.lang.Exception
JobRepository
have been
set.afterPropertiesSet
in interface org.springframework.beans.factory.InitializingBean
java.lang.Exception