easy-batch job 配置
创建一个batch job
我们可以通过JobBuilder创建job
默认job 的名称为job
- 参考
Job job = new JobBuilder()
.named("myJob")
.build();
// Or
Job job = JobBuilder.aNewJob()
.named("myJob")
.build();
运行job
- 同步模式
//Either by calling the job directly
JobReport jobReport = job.call();
// Or using the org.easybatch.core.job.JobExecutor API
JobExecutor jobExecutor = new JobExecutor();
JobReport jobReport = jobExecutor.execute(job);
// Or using a java.util.concurrent.ExecutorService
ExecutorService executorService = ..;
JobReport jobReport = executorService.submit(job).get();
- 异步模式
// Using the org.easybatch.core.job.JobExecutor API
JobExecutor jobExecutor = new JobExecutor();
Future<JobReport> jobReport = jobExecutor.submit(job);
// Or using a java.util.concurrent.ExecutorService
ExecutorService executorService = ..;
Future<JobReport> jobReport = executorService.submit(job);
- 说明
注意在应用结束的时候应该关闭JobExecutor,可以通过java runtime 的钩子,或者spring 的bean 管理模式
job 的参数
- 包含的参数
来自官方文档
- 编程模式
Job job = JobBuilder.aNewJob()
.batchSize(50)
.errorThreshold(10)
.enableJmx(true)
.enableBatchScanning(true)
.build();