org.springframework.batch.core.step.tasklet.Tasklet Java Examples

The following examples show how to use org.springframework.batch.core.step.tasklet.Tasklet. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: JobConfiguration.java    From tutorials with MIT License 6 votes vote down vote up
@Bean
public Job job2() {
    return jobBuilderFactory.get("job2")
        .start(stepBuilderFactory.get("job2step1")
            .tasklet(new Tasklet() {
                @Override
                public RepeatStatus execute(
                    StepContribution contribution,
                    ChunkContext chunkContext)
                    throws Exception {
                    LOGGER
                        .info("This job is from Baeldung");
                    return RepeatStatus.FINISHED;
                }
            })
            .build())
        .build();
}
 
Example #2
Source File: JobConfiguration.java    From spring-cloud-task with Apache License 2.0 5 votes vote down vote up
@Bean
public Job job2() {
	return this.jobBuilderFactory.get("job2")
		.start(this.stepBuilderFactory.get("job2step1")
			.tasklet(new Tasklet() {
				@Override
				public RepeatStatus execute(StepContribution contribution, ChunkContext chunkContext) throws Exception {
					logger.info("Job2 was run");
					return RepeatStatus.FINISHED;
				}
			})
			.build())
		.build();
}
 
Example #3
Source File: JobConfiguration.java    From spring-cloud-task with Apache License 2.0 5 votes vote down vote up
@Bean
public Job job1() {
	return this.jobBuilderFactory.get("job1")
		.start(this.stepBuilderFactory.get("job1step1")
			.tasklet(new Tasklet() {
				@Override
				public RepeatStatus execute(StepContribution contribution, ChunkContext chunkContext) throws Exception {
					logger.info("Job1 was run");
					return RepeatStatus.FINISHED;
				}
			})
			.build())
		.build();
}
 
Example #4
Source File: TaskBatchEventListenerBeanPostProcessor.java    From spring-cloud-task with Apache License 2.0 5 votes vote down vote up
@Override
public Object postProcessBeforeInitialization(Object bean, String beanName)
		throws BeansException {

	registerJobExecutionEventListener(bean);

	if (bean instanceof AbstractStep) {
		registerStepExecutionEventListener(bean);
		if (bean instanceof TaskletStep) {
			TaskletStep taskletStep = (TaskletStep) bean;
			Tasklet tasklet = taskletStep.getTasklet();
			registerChunkEventsListener(bean);

			if (tasklet instanceof ChunkOrientedTasklet) {
				Field chunkProviderField = ReflectionUtils
						.findField(ChunkOrientedTasklet.class, "chunkProvider");
				ReflectionUtils.makeAccessible(chunkProviderField);
				SimpleChunkProvider chunkProvider = (SimpleChunkProvider) ReflectionUtils
						.getField(chunkProviderField, tasklet);
				Field chunkProcessorField = ReflectionUtils
						.findField(ChunkOrientedTasklet.class, "chunkProcessor");
				ReflectionUtils.makeAccessible(chunkProcessorField);
				SimpleChunkProcessor chunkProcessor = (SimpleChunkProcessor) ReflectionUtils
						.getField(chunkProcessorField, tasklet);
				registerItemReadEvents(chunkProvider);
				registerSkipEvents(chunkProvider);
				registerItemProcessEvents(chunkProcessor);
				registerItemWriteEvents(chunkProcessor);
				registerSkipEvents(chunkProcessor);
			}
		}
	}

	return bean;
}
 
Example #5
Source File: JobSkipConfiguration.java    From spring-cloud-task with Apache License 2.0 5 votes vote down vote up
@Bean
public Step step1() {
	return this.stepBuilderFactory.get("step1").tasklet(new Tasklet() {
		@Override
		public RepeatStatus execute(StepContribution contribution,
				ChunkContext chunkContext) throws Exception {
			System.out.println("Executed");
			return RepeatStatus.FINISHED;
		}
	}).build();
}
 
Example #6
Source File: JobConfiguration.java    From spring-cloud-task with Apache License 2.0 5 votes vote down vote up
@Bean
public Step step1() {
	return this.stepBuilderFactory.get("step1").tasklet(new Tasklet() {
		@Override
		public RepeatStatus execute(StepContribution contribution,
				ChunkContext chunkContext) throws Exception {
			System.out.println("Executed");
			return RepeatStatus.FINISHED;
		}
	}).build();
}
 
Example #7
Source File: TaskBatchExecutionListenerTests.java    From spring-cloud-task with Apache License 2.0 5 votes vote down vote up
@Bean
public Job job() {
	return this.jobBuilderFactory.get("job")
			.start(this.stepBuilderFactory.get("step1").tasklet(new Tasklet() {
				@Override
				public RepeatStatus execute(StepContribution contribution,
						ChunkContext chunkContext) throws Exception {
					System.out.println("Executed");
					return RepeatStatus.FINISHED;
				}
			}).build()).build();
}
 
Example #8
Source File: TaskBatchExecutionListenerTests.java    From spring-cloud-task with Apache License 2.0 5 votes vote down vote up
@Bean
public FactoryBean<Job> job() {
	return new FactoryBean<Job>() {
		@Override
		public Job getObject() throws Exception {
			return JobFactoryBeanConfiguration.this.jobBuilderFactory.get("job")
					.start(JobFactoryBeanConfiguration.this.stepBuilderFactory
							.get("step1").tasklet(new Tasklet() {
								@Override
								public RepeatStatus execute(
										StepContribution contribution,
										ChunkContext chunkContext)
										throws Exception {
									System.out.println("Executed");
									return RepeatStatus.FINISHED;
								}
							}).build())
					.build();
		}

		@Override
		public Class<?> getObjectType() {
			return Job.class;
		}

		@Override
		public boolean isSingleton() {
			return true;
		}
	};
}
 
Example #9
Source File: TaskBatchExecutionListenerTests.java    From spring-cloud-task with Apache License 2.0 5 votes vote down vote up
@Bean
public Job job() {
	return this.jobBuilderFactory.get("job")
			.start(this.stepBuilderFactory.get("step1").tasklet(new Tasklet() {
				@Override
				public RepeatStatus execute(StepContribution contribution,
						ChunkContext chunkContext) throws Exception {
					System.out.println("Executed");
					return RepeatStatus.FINISHED;
				}
			}).build()).build();
}
 
Example #10
Source File: TaskBatchExecutionListenerTests.java    From spring-cloud-task with Apache License 2.0 5 votes vote down vote up
@Bean
public Job job1() {
	return this.jobBuilderFactory.get("job1").start(
			this.stepBuilderFactory.get("job1step1").tasklet(new Tasklet() {
				@Override
				public RepeatStatus execute(StepContribution contribution,
						ChunkContext chunkContext) throws Exception {
					System.out.println("Executed job1");
					return RepeatStatus.FINISHED;
				}
			}).build()).build();
}
 
Example #11
Source File: TaskBatchExecutionListenerTests.java    From spring-cloud-task with Apache License 2.0 5 votes vote down vote up
@Bean
public Job job2() {
	return this.jobBuilderFactory.get("job2").start(
			this.stepBuilderFactory.get("job2step1").tasklet(new Tasklet() {
				@Override
				public RepeatStatus execute(StepContribution contribution,
						ChunkContext chunkContext) throws Exception {
					System.out.println("Executed job2");
					return RepeatStatus.FINISHED;
				}
			}).build()).build();
}
 
Example #12
Source File: TaskJobLauncherCommandLineRunnerCoreTests.java    From spring-cloud-task with Apache License 2.0 5 votes vote down vote up
@Before
public void init() {
	this.jobs = new JobBuilderFactory(this.jobRepository);
	this.steps = new StepBuilderFactory(this.jobRepository, this.transactionManager);
	Tasklet tasklet = (contribution, chunkContext) -> RepeatStatus.FINISHED;
	this.step = this.steps.get("step").tasklet(tasklet).build();
	this.job = this.jobs.get("job").start(this.step).build();
	this.runner = new TaskJobLauncherCommandLineRunner(this.jobLauncher,
			this.jobExplorer, this.jobRepository, new TaskBatchProperties());

}
 
Example #13
Source File: TaskJobLauncherCommandLineRunnerTests.java    From spring-cloud-task with Apache License 2.0 5 votes vote down vote up
@Bean
public Job job() {
	return this.jobBuilderFactory.get("job")
			.start(this.stepBuilderFactory.get("step1").tasklet(new Tasklet() {
				@Override
				public RepeatStatus execute(StepContribution contribution,
						ChunkContext chunkContext) {
					System.out.println("Executed");
					return RepeatStatus.FINISHED;
				}
			}).build()).build();
}
 
Example #14
Source File: TaskJobLauncherCommandLineRunnerTests.java    From spring-cloud-task with Apache License 2.0 5 votes vote down vote up
@Bean
public Job jobFail() {
	return this.jobBuilderFactory.get("jobA")
			.start(this.stepBuilderFactory.get("step1").tasklet(new Tasklet() {
				@Override
				public RepeatStatus execute(StepContribution contribution,
						ChunkContext chunkContext) throws Exception {
					System.out.println("Executed");
					throw new IllegalStateException("WHOOPS");
				}
			}).build()).build();
}
 
Example #15
Source File: TaskJobLauncherCommandLineRunnerTests.java    From spring-cloud-task with Apache License 2.0 5 votes vote down vote up
@Bean
public Job jobFun() {
	return this.jobBuilderFactory.get("jobSucceed").start(
			this.stepBuilderFactory.get("step1Succeed").tasklet(new Tasklet() {
				@Override
				public RepeatStatus execute(StepContribution contribution,
						ChunkContext chunkContext) {
					System.out.println("Executed");
					return RepeatStatus.FINISHED;
				}
			}).build()).build();
}
 
Example #16
Source File: JobConfiguration.java    From tutorials with MIT License 5 votes vote down vote up
@Bean
public Job job() {
    return jobBuilderFactory.get("job").start(stepBuilderFactory.get("jobStep1").tasklet(new Tasklet() {
        @Override
        public RepeatStatus execute(StepContribution contribution, ChunkContext chunkContext) throws Exception {
            logger.info("Job was run");
            return RepeatStatus.FINISHED;
        }
    }).build()).build();
}
 
Example #17
Source File: JobConfiguration.java    From tutorials with MIT License 5 votes vote down vote up
@Bean
public Step step1() {
    return this.stepBuilderFactory.get("job1step1")
        .tasklet(new Tasklet() {
            @Override
            public RepeatStatus execute(
                StepContribution contribution,
                ChunkContext chunkContext)
                throws Exception {
                LOGGER.info("Tasklet has run");
                return RepeatStatus.FINISHED;
            }
        }).build();
}
 
Example #18
Source File: CustomerReportJobConfig.java    From spring-batch-article with MIT License 5 votes vote down vote up
@Bean
public Tasklet tasklet() {
    return (contribution, chunkContext) -> {
        log.info("Executing tasklet step");
        return RepeatStatus.FINISHED;
    };
}
 
Example #19
Source File: SimpleBatchApplication.java    From Software-Architecture-with-Spring-5.0 with MIT License 5 votes vote down vote up
@Bean
public Step ourBatchStep() {
	return stepBuilderFactory.get("stepPackPub1")
			.tasklet(new Tasklet() {
				public RepeatStatus execute(StepContribution contribution, ChunkContext chunkContext) {
					return null;
				}
			})
			.build();
}
 
Example #20
Source File: ComposedRunnerVisitorConfiguration.java    From composed-task-runner with Apache License 2.0 5 votes vote down vote up
private Step createTaskletStepWithListener(final String taskName,
		StepExecutionListener stepExecutionListener) {
	return this.steps.get(taskName)
			.tasklet(new Tasklet() {
				@Override
				public RepeatStatus execute(StepContribution contribution, ChunkContext chunkContext) throws Exception {
					return RepeatStatus.FINISHED;
				}
			})
			.transactionAttribute(getTransactionAttribute())
			.listener(stepExecutionListener)
			.build();
}
 
Example #21
Source File: ComposedRunnerVisitorConfiguration.java    From composed-task-runner with Apache License 2.0 5 votes vote down vote up
private Step createTaskletStep(final String taskName) {
	return this.steps.get(taskName)
			.tasklet(new Tasklet() {
				@Override
				public RepeatStatus execute(StepContribution contribution, ChunkContext chunkContext) throws Exception {
					return RepeatStatus.FINISHED;
				}
			})
			.transactionAttribute(getTransactionAttribute())
			.build();
}
 
Example #22
Source File: StepService0005.java    From seed with Apache License 2.0 5 votes vote down vote up
private Tasklet nextBizDateTasklet(){
    return new Tasklet() {
        @Override
        public RepeatStatus execute(StepContribution contribution, ChunkContext chunkContext) {
            //入参contribution=org.springframework.batch.core.StepContribution@153ef3fc[readCount=0,writeCount=0,filterCount=0,parentSkipCount=0,readSkipCount=0,writeSkipCount=0,processSkipCount=0,exitStatus=exitCode=EXECUTING;exitDescription=],chunkContext=org.springframework.batch.core.scope.context.ChunkContext@2313a648[stepContext=SynchronizedAttributeAccessor: [], stepExecutionContext={batch.taskletType=com.jadyer.seed.controller.batch.javaconfig.StepService0005$1, batch.stepType=org.springframework.batch.core.step.tasklet.TaskletStep}, jobExecutionContext={}, jobParameters={time=1536145118798},complete=false,attributes={}],chunkContext.getStepContext=org.springframework.batch.core.scope.context.StepContext@3441dec5[stepExecution=StepExecution: id=23, version=1, name=step0005, status=STARTED, exitStatus=EXECUTING, readCount=0, filterCount=0, writeCount=0 readSkipCount=0, writeSkipCount=0, processSkipCount=0, commitCount=0, rollbackCount=0, exitDescription=,callbacks={},propertyContext=<null>,support=org.springframework.batch.repeat.context.SynchronizedAttributeAccessor$1@0]
            LogUtil.getLogger().info("入参contribution={},chunkContext={},chunkContext.getStepContext={}", ReflectionToStringBuilder.toString(contribution), ReflectionToStringBuilder.toString(chunkContext), ReflectionToStringBuilder.toString(chunkContext.getStepContext()));
            try {
                TimeUnit.SECONDS.sleep(5);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
            return RepeatStatus.FINISHED;
        }
    };
}
 
Example #23
Source File: BatchConfiguration.java    From spring-graalvm-native with Apache License 2.0 5 votes vote down vote up
@Bean
public Step step1() {
	return this.stepBuilderFactory.get("step1")
			.tasklet(new Tasklet() {
				@Override
				public RepeatStatus execute(StepContribution stepContribution, ChunkContext chunkContext) throws Exception {
					System.out.println(">> This was run in a Spring Batch app!");

					return RepeatStatus.FINISHED;
				}
			}).build();
}
 
Example #24
Source File: BatchConfiguration.java    From journaldev with MIT License 5 votes vote down vote up
@Bean
public Step step1() {
  return stepBuilderFactory.get("step1")
      .tasklet(new Tasklet() {
        public RepeatStatus execute(StepContribution contribution, ChunkContext chunkContext) {
          return null;
        }
      })
      .build();
}
 
Example #25
Source File: ComposedRunnerVisitorConfiguration.java    From spring-cloud-dataflow with Apache License 2.0 5 votes vote down vote up
private Step createTaskletStepWithListener(final String taskName,
		StepExecutionListener stepExecutionListener) {
	return this.steps.get(taskName)
			.tasklet(new Tasklet() {
				@Override
				public RepeatStatus execute(StepContribution contribution, ChunkContext chunkContext) throws Exception {
					return RepeatStatus.FINISHED;
				}
			})
			.transactionAttribute(getTransactionAttribute())
			.listener(stepExecutionListener)
			.build();
}
 
Example #26
Source File: ComposedRunnerVisitorConfiguration.java    From spring-cloud-dataflow with Apache License 2.0 5 votes vote down vote up
private Step createTaskletStep(final String taskName) {
	return this.steps.get(taskName)
			.tasklet(new Tasklet() {
				@Override
				public RepeatStatus execute(StepContribution contribution, ChunkContext chunkContext) throws Exception {
					return RepeatStatus.FINISHED;
				}
			})
			.transactionAttribute(getTransactionAttribute())
			.build();
}
 
Example #27
Source File: AddressImportJobConfiguration.java    From spring-batch-lightmin with Apache License 2.0 5 votes vote down vote up
@Bean
public Step deleteFileStep(final Tasklet deleteFileTasklet,
                           final StepBuilderFactory stepBuilderFactory) {
    return stepBuilderFactory
            .get("deleteFileStep")
            .tasklet(deleteFileTasklet)
            .build();
}
 
Example #28
Source File: AddressImportJobConfiguration.java    From spring-batch-lightmin with Apache License 2.0 5 votes vote down vote up
@Bean
@JobScope
public Tasklet deleteFileTasklet(@Value("#{jobParameters['fileSource']}") final String pathToFile) {
    return (contribution, chunkContext) -> {
        final File file = new File(pathToFile);
        final boolean deleted = file.delete();
        final RepeatStatus repeatStatus;
        if (deleted) {
            repeatStatus = RepeatStatus.FINISHED;
        } else {
            repeatStatus = RepeatStatus.CONTINUABLE;
        }
        return repeatStatus;
    };
}
 
Example #29
Source File: BatchEventsApplication.java    From spring-cloud-task with Apache License 2.0 5 votes vote down vote up
@Bean
public Step step1() {
	return this.stepBuilderFactory.get("step1")
		.tasklet(new Tasklet() {
			@Override
			public RepeatStatus execute(StepContribution contribution, ChunkContext chunkContext) throws Exception {
				System.out.println("Tasklet has run");
				return RepeatStatus.FINISHED;
			}
		}).build();
}
 
Example #30
Source File: JobConfiguration.java    From spring-cloud-task with Apache License 2.0 5 votes vote down vote up
@Bean
@StepScope
public Tasklet workerTasklet(
	final @Value("#{stepExecutionContext['partitionNumber']}") Integer partitionNumber) {

	return new Tasklet() {
		@Override
		public RepeatStatus execute(StepContribution contribution, ChunkContext chunkContext) throws Exception {
			System.out.println("This tasklet ran partition: " + partitionNumber);

			return RepeatStatus.FINISHED;
		}
	};
}