Giriş
run() metodu aracılığıyla belirtilen Job nesnesini belirtilen JobParameters ile çalıştırır.
Tanımlama
Örnek
Şöyle yaparız.
Şöyle yaparız.
Örnek
Elimizde bir tane Job bean olsun. Job nesnesi normalde bean olmak zorunda değil.
Şöyle yaparız.
Şöyle yaparız.
Metodun imzası şöyle. JobExecution nesnesi döner.
Şöyle yaparız
Elimizde şöyle bir kod olsun
Controller içinde şöyle yaparız.
Örnek
Şöyle yaparız.
Örnek
Şöyle yaparız.
Şöyle yaparız.
run() metodu aracılığıyla belirtilen Job nesnesini belirtilen JobParameters ile çalıştırır.
Tanımlama
Örnek
Şöyle yaparız.
<bean id="jobLauncher"
     class="org.springframework.batch.core.launch.support.SimpleJobLauncher">
    <property name="jobRepository" ref="jobRepository" />
    <property name="taskExecutor">
        <bean class="org.springframework.core.task.SimpleAsyncTaskExecutor" />
    </property>
</bean>Şöyle yaparız.
@Bean
public JobLauncher simpleJobLauncher() throws Exception {
  SimpleJobLauncher jobLauncher = new SimpleJobLauncher();
  ...
  return jobLauncher;
}Örnek
Elimizde bir tane Job bean olsun. Job nesnesi normalde bean olmak zorunda değil.
@Bean
public Step step1() {
  return stepBuilderFactory.get("step1")
    .<Customer, Customer> chunk(1000)
    .reader(customerItemReader())
    .writer(customerItemWriter())
    .build();
}
@Bean
public Job job() {
  return jobBuilderFactory.get("job")
    .start(step1())
    .build();
}  
@EnableBatchProcessing
public class SpringBatchApplication implements CommandLineRunner {
  @Autowired
  private JobLauncher jobLauncher;
  @Autowired
  private Job job;
  public static void main(String[] args) {
    SpringApplication.run(SpringBatchApplication.class, args);
  }
  @Override
  public void run(String... args) throws Exception {
    JobParameters jobParameters = new JobParametersBuilder()
      .addString("UUID", UUID.randomUUID().toString())
      .toJobParameters();
    JobExecution execution = jobLauncher.run(job, jobParameters);
    System.out.println("STATUS :: "+execution.getStatus());
   }
}
Şöyle yaparız.
SimpleJobLauncher jobLauncher = new SimpleJobLauncher();
Şöyle yaparız.
jobLauncher.afterPropertiesSet();Metodun imzası şöyle. JobExecution nesnesi döner.
public JobExecution run(Job job, JobParameters jobParameters)
  throws JobExecutionAlreadyRunningException, JobRestartException,
         JobInstanceAlreadyCompleteException, JobParametersInvalidExceptionŞöyle yaparız
Job job =  ...;
JobParameters jobParameters = ...;
try {
  JobExecution jobExecution = jobLauncher.run(job, jobParameters);
} catch (JobExecutionAlreadyRunningException | JobRestartException
   | JobInstanceAlreadyCompleteException | JobParametersInvalidException e) {
  ...
}Elimizde şöyle bir kod olsun
JobParametersBuilder paramsBuilder = new JobParametersBuilder();
paramsBuilder.addString("delimiter", "yourCustomDelimiter");jobLauncher.run(job, paramsBuilder.toJobParameters());Controller içinde şöyle yaparız.
@Autowired
JobLauncher jobLauncher;
@RequestMapping(value="/trigger-job", method = RequestMethod.GET)
public Long workHard() throws Exception {
  JobParameters jobParameters = new JobParametersBuilder().
    addLong("time", System.currentTimeMillis())
    .toJobParameters();
  JobExecution jobExecution = jobLauncher.run(myJob, jobParameters);
  ...
}Örnek
Şöyle yaparız.
@Configuration
public class BatchConfig {
  @Autowired
  JobRepository jobRepository;
  @Bean
  public JobLauncher simpleJobLauncher() throws Exception {
    SimpleJobLauncher jobLauncher = new SimpleJobLauncher();
    jobLauncher.setJobRepository(jobRepository);
    ...
    return jobLauncher;
  }
}Örnek
Şöyle yaparız.
jobLauncher.setTaskExecutor(new SimpleAsyncTaskExecutor());Şöyle yaparız.
@Bean
public ThreadPoolTaskExecutor taskExecutor() {
  ThreadPoolTaskExecutor taskExecutor = new ThreadPoolTaskExecutor();
  taskExecutor.setCorePoolSize(15);
  taskExecutor.setMaxPoolSize(20);
  taskExecutor.setQueueCapacity(30);
  return taskExecutor;
}
@Bean
public JobLauncher jobLauncher(ThreadPoolTaskExecutor taskExecutor,
  JobRepository jobRepository) {
  SimpleJobLauncher jobLauncher = new SimpleJobLauncher();
  jobLauncher.setTaskExecutor(taskExecutor);
  jobLauncher.setJobRepository(jobRepository);
  return jobLauncher;
} 
Hiç yorum yok:
Yorum Gönder