Java Reference
In-Depth Information
The configuration in Listing 6-8 assumes you're using the POM file that is included in the Spring
Batch project. If you aren't, you need to include the version number in place of the property provided.
With the appropriate code now available on your classpath, you can write
SpringBatchQuartzJobLauncher . Before you write the code, however, let's talk about what it's going to do.
In this case, SpringBatchQuartzJobLauncher takes the place of JMXJobLauncher from Chapter 5 and then
some. JMXJobLauncher didn't accept any job parameters as part of the job execution. For this example,
your job requires two parameters: the path to the directory you wish to empty and the age of a file that
you want to delete. For the sake of simplicity, you delete all files that haven't been modified for the given
period of time.
Not only can your Quartz job runner accept incoming parameters, but to prevent the job from not
being able to be run more than once, you use Spring Batch's parameter-incrementer functionality
(discussed in Chapter 4) to have a unique set of parameters with each run. Listing 6-9 shows
SpringBatchQuartzJobLauncher in its entirety.
Listing 6-9. SpringBatchQuartzJobLauncher
package com.apress.springbatch.chapter6;
import java.util.List;
import java.util.Map;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.batch.core.Job;
import org.springframework.batch.core.JobInstance;
import org.springframework.batch.core.JobParameter;
import org.springframework.batch.core.JobParameters;
import org.springframework.batch.core.JobParametersBuilder;
import org.springframework.batch.core.JobParametersIncrementer;
import org.springframework.batch.core.configuration.JobLocator;
import org.springframework.batch.core.explore.JobExplorer;
import org.springframework.batch.core.launch.JobLauncher;
import org.springframework.batch.core.launch.JobParametersNotFoundException;
import org.springframework.scheduling.quartz.QuartzJobBean;
public class SpringBatchQuartzJobLauncher extends QuartzJobBean {
private JobLauncher jobLauncher;
private JobLocator jobLocator;
private JobExplorer jobExplorer;
private Map<String, String> jobParameters;
public static final String JOB_NAME = "jobName";
private static final Logger log = LoggerFactory
.getLogger(SpringBatchQuartzJobLauncher.class);
@Override
@SuppressWarnings("unchecked")
protected void executeInternal(JobExecutionContext context)
 
Search WWH ::




Custom Search