org.springframework.batch.core.launch.support
Class SimpleJobLauncher

java.lang.Object
  extended by org.springframework.batch.core.launch.support.SimpleJobLauncher
All Implemented Interfaces:
JobLauncher, InitializingBean

public class SimpleJobLauncher
extends Object
implements JobLauncher, InitializingBean

Simple implementation of the 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.

Since:
1.0
Author:
Lucas Ward
See Also:
JobRepository, TaskExecutor

Field Summary
protected static Log logger
           
 
Constructor Summary
SimpleJobLauncher()
           
 
Method Summary
 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 JobRepsitory.
 void setTaskExecutor(TaskExecutor taskExecutor)
          Set the TaskExecutor.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

logger

protected static final Log logger
Constructor Detail

SimpleJobLauncher

public SimpleJobLauncher()
Method Detail

run

public JobExecution run(Job job,
                        JobParameters jobParameters)
                 throws JobExecutionAlreadyRunningException,
                        JobRestartException,
                        JobInstanceAlreadyCompleteException
Run the provided job with the given 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.

Specified by:
run in interface JobLauncher
Parameters:
job - the job to be run.
jobParameters - the JobParameters for this particular execution.
Returns:
JobExecutionAlreadyRunningException if the JobInstance already exists and has an execution already running.
Throws:
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 successfully
JobExecutionAlreadyRunningException - if the JobInstance identified by the properties already has an execution running.

setJobRepository

public void setJobRepository(JobRepository jobRepository)
Set the JobRepsitory.

Parameters:
jobRepository -

setTaskExecutor

public void setTaskExecutor(TaskExecutor taskExecutor)
Set the TaskExecutor. (Optional)

Parameters:
taskExecutor -

afterPropertiesSet

public void afterPropertiesSet()
                        throws Exception
Ensure the required dependencies of a JobRepository have been set.

Specified by:
afterPropertiesSet in interface InitializingBean
Throws:
Exception


Copyright © 2009 SpringSource. All Rights Reserved.