Java Code Examples for org.springframework.batch.core.launch.support.SimpleJobLauncher

The following examples show how to use org.springframework.batch.core.launch.support.SimpleJobLauncher. These examples are extracted from open source projects. 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 Project: spring-cloud-dataflow   Source File: JobDependencies.java    License: Apache License 2.0 6 votes vote down vote up
@Bean
public SimpleJobServiceFactoryBean simpleJobServiceFactoryBean(DataSource dataSource,
		JobRepositoryFactoryBean repositoryFactoryBean, JobExplorer jobExplorer,
		PlatformTransactionManager dataSourceTransactionManager) {
	SimpleJobServiceFactoryBean factoryBean = new SimpleJobServiceFactoryBean();
	factoryBean.setDataSource(dataSource);
	try {
		factoryBean.setJobRepository(repositoryFactoryBean.getObject());
		factoryBean.setJobLauncher(new SimpleJobLauncher());
		factoryBean.setJobExplorer(jobExplorer);
		factoryBean.setTransactionManager(dataSourceTransactionManager);
	}
	catch (Exception e) {
		throw new IllegalStateException(e);
	}
	return factoryBean;
}
 
Example 2
Source Project: spring-cloud   Source File: SpringBatchConfiguration.java    License: Apache License 2.0 5 votes vote down vote up
private JobLauncher createJobLauncher() throws Exception {
    SimpleJobLauncher jobLauncher = new SimpleJobLauncher();
    jobLauncher.setJobRepository(jobRepository);
    jobLauncher.setTaskExecutor(new SimpleAsyncTaskExecutor());
    jobLauncher.afterPropertiesSet();
    return jobLauncher;
}
 
Example 3
Source Project: blackduck-alert   Source File: ApplicationConfiguration.java    License: Apache License 2.0 5 votes vote down vote up
@Bean
public SimpleJobLauncher jobLauncher() {
    SimpleJobLauncher launcher = new SimpleJobLauncher();
    try {
        launcher.setJobRepository(jobRepository());
    } catch (Exception ex) {
        logger.error("Creating job launcher bean", ex);
    }
    return launcher;
}
 
Example 4
Source Project: j360-dubbo-app-all   Source File: JobTaskScheduled.java    License: Apache License 2.0 5 votes vote down vote up
public void run() {
    long timeCount = count.incrementAndGet();
    log.info("任务执行开始 [count={}, date={}]",timeCount, DateFormatUtil.formatDate(DateFormatUtil.PATTERN_DEFAULT_ON_SECOND, new Date()));
    SimpleJobLauncher launcher = new SimpleJobLauncher();
    launcher.setJobRepository(jobRepository);
    launcher.setTaskExecutor(new SimpleAsyncTaskExecutor());
    try {
        launcher.run(batchJob, new JobParameters());
    } catch (Exception e) {
        log.error("任务执行失败 [count={}, date={}]", timeCount, DateFormatUtil.formatDate(DateFormatUtil.PATTERN_DEFAULT_ON_SECOND, new Date()),e);
    } finally {
        log.info("任务执行结束 [count={}, date={}]",timeCount, DateFormatUtil.formatDate(DateFormatUtil.PATTERN_DEFAULT_ON_SECOND, new Date()));
    }

}
 
Example 5
Source Project: spring-cloud-dataflow   Source File: TaskConfiguration.java    License: Apache License 2.0 5 votes vote down vote up
@Bean
public SimpleJobServiceFactoryBean simpleJobServiceFactoryBean(DataSource dataSource,
		JobRepositoryFactoryBean repositoryFactoryBean, JobExplorer jobExplorer,
		PlatformTransactionManager dataSourceTransactionManager) throws Exception {
	SimpleJobServiceFactoryBean factoryBean = new SimpleJobServiceFactoryBean();
	factoryBean.setDataSource(dataSource);
	factoryBean.setJobRepository(repositoryFactoryBean.getObject());
	factoryBean.setJobLauncher(new SimpleJobLauncher());
	factoryBean.setDataSource(dataSource);
	factoryBean.setJobExplorer(jobExplorer);
	factoryBean.setTransactionManager(dataSourceTransactionManager);
	return factoryBean;
}
 
Example 6
@Before
public void init() {
    MockitoAnnotations.initMocks(this);
    this.listenerService = new DefaultListenerService(this.beanRegistrar, this.jobRegistry, this.jobRepository);
    ReflectionTestUtils.setField(this.listenerService, "applicationContext", this.applicationContext);
    this.job = DomainTestHelper.createJob("testJob");
    this.jobLauncher = new SimpleJobLauncher();
}
 
Example 7
@Test
public void refreshSchedulerForJobTest() {
    final String beanName = "schedulerBean";
    final JobSchedulerConfiguration jobSchedulerConfiguration = DomainTestHelper.createJobSchedulerConfiguration(null,
            10L, 10L, JobSchedulerType.PERIOD);
    jobSchedulerConfiguration.setBeanName(beanName);
    jobSchedulerConfiguration.setTaskExecutorType(TaskExecutorType.ASYNCHRONOUS);
    final JobConfiguration jobConfiguration = DomainTestHelper.createJobConfiguration(jobSchedulerConfiguration);
    final Map<String, Object> jobParameters = new HashMap<>();
    jobParameters.put("LONG", 10L);
    jobParameters.put("DOUBLE", 20.2);
    jobParameters.put("STRING", "test");
    jobParameters.put("DATE", "2015/03/27 23:19:24:120");
    jobParameters.put("DATE", "2015/03/27");
    jobConfiguration.setJobParameters(jobParameters);
    final SchedulerConstructorWrapper schedulerConstructorWrapper = new SchedulerConstructorWrapper();
    schedulerConstructorWrapper.setJob(DomainTestHelper.createJob("sampleJob"));
    schedulerConstructorWrapper.setJobConfiguration(jobConfiguration);
    schedulerConstructorWrapper.setJobIncrementer(JobIncrementer.NONE);
    schedulerConstructorWrapper.setJobLauncher(new SimpleJobLauncher());
    schedulerConstructorWrapper.setJobParameters(new JobParametersBuilder().toJobParameters());
    //scheduler = new PeriodScheduler(schedulerConstructorWrapper);
    when(this.applicationContext.containsBean(beanName)).thenReturn(Boolean.TRUE);
    when(this.applicationContext.getBean(beanName, Scheduler.class)).thenReturn(this.scheduler);
    when(this.scheduler.getSchedulerStatus()).thenReturn(SchedulerStatus.INITIALIZED);
    this.schedulerService.refreshSchedulerForJob(jobConfiguration);
    verify(this.scheduler, times(1)).terminate();
}
 
Example 8
@Test
public void refreshSchedulerForJobCronTest() {
    final String beanName = "schedulerBean";
    final JobSchedulerConfiguration jobSchedulerConfiguration = DomainTestHelper.createJobSchedulerConfiguration("some " +
                    "Cron",
            null, null, JobSchedulerType.CRON);
    jobSchedulerConfiguration.setBeanName(beanName);
    jobSchedulerConfiguration.setTaskExecutorType(TaskExecutorType.ASYNCHRONOUS);
    final JobConfiguration jobConfiguration = DomainTestHelper.createJobConfiguration(jobSchedulerConfiguration);
    final Map<String, Object> jobParameters = new HashMap<>();
    jobParameters.put("LONG", 10L);
    jobParameters.put("DOUBLE", 20.2);
    jobParameters.put("STRING", "test");
    jobParameters.put("DATE", "2015/03/27 23:19:24:120");
    jobParameters.put("DATE", "2015/03/27");
    jobConfiguration.setJobParameters(jobParameters);
    final SchedulerConstructorWrapper schedulerConstructorWrapper = new SchedulerConstructorWrapper();
    schedulerConstructorWrapper.setJob(DomainTestHelper.createJob("sampleJob"));
    schedulerConstructorWrapper.setJobConfiguration(jobConfiguration);
    schedulerConstructorWrapper.setJobIncrementer(JobIncrementer.NONE);
    schedulerConstructorWrapper.setJobLauncher(new SimpleJobLauncher());
    schedulerConstructorWrapper.setJobParameters(new JobParametersBuilder().toJobParameters());
    //scheduler = new PeriodScheduler(schedulerConstructorWrapper);
    when(this.applicationContext.containsBean(beanName)).thenReturn(Boolean.TRUE);
    when(this.applicationContext.getBean(beanName, Scheduler.class)).thenReturn(this.scheduler);
    when(this.scheduler.getSchedulerStatus()).thenReturn(SchedulerStatus.INITIALIZED);
    this.schedulerService.refreshSchedulerForJob(jobConfiguration);
    verify(this.scheduler, times(1)).terminate();
}
 
Example 9
@Bean(name = "defaultAsyncJobLauncher")
public JobLauncher defaultAsyncJobLauncher(final JobRepository jobRepository) {
    final SimpleJobLauncher jobLauncher = new SimpleJobLauncher();
    jobLauncher.setJobRepository(jobRepository);
    jobLauncher.setTaskExecutor(new SimpleAsyncTaskExecutor());
    return jobLauncher;
}
 
Example 10
@Override
public JobLauncher getJobLauncher() {
	SimpleJobLauncher launcher = new SimpleJobLauncher();
	launcher.setJobRepository(this.jobRepository);
	launcher.setTaskExecutor(new SyncTaskExecutor());
	return launcher;
}
 
Example 11
protected JobLauncher createJobLauncher() throws Exception {
	SimpleJobLauncher jobLauncher = new SimpleJobLauncher();
	jobLauncher.setJobRepository(getJobRepository());
	jobLauncher.setTaskExecutor(new ConcurrentTaskExecutor());
	jobLauncher.afterPropertiesSet();
	return jobLauncher;
}
 
Example 12
Source Project: batchers   Source File: ThreadedPerformanceTest.java    License: Apache License 2.0 5 votes vote down vote up
@Before
public void setUp() throws Exception {
    mockServer = MockRestServiceServer.createServer(restTemplate);
    SmtpServerStub.start();
    jobParams = new JobParametersBuilder()
            .addLong("month", 2L)
            .addLong("year", 2014L).toJobParameters();

    employeeGeneratorService.resetEmployees(NUMBER_OF_EMPLOYEES);
    runningTimeService.setMaximumTime(51);
    runningTimeService.setMinimumTime(50);

    jobLauncher = new SimpleJobLauncher();
    jobLauncher.setJobRepository(jobRepository);
}
 
Example 13
private JobLauncher createJobLauncher() throws Exception {
	SimpleJobLauncher simpleJobLauncher = new SimpleJobLauncher();
	simpleJobLauncher.setJobRepository(jobRepository);
	simpleJobLauncher.setTaskExecutor(taskExecutor);
	simpleJobLauncher.afterPropertiesSet();
	return simpleJobLauncher;
}
 
Example 14
Source Project: tutorials   Source File: SpringbatchPartitionConfig.java    License: MIT License 5 votes vote down vote up
public JobLauncher getJobLauncher() throws Exception {
    SimpleJobLauncher jobLauncher = new SimpleJobLauncher();
    // SimpleJobLauncher's methods Throws Generic Exception,
    // it would have been better to have a specific one
    jobLauncher.setJobRepository(getJobRepository());
    jobLauncher.afterPropertiesSet();
    return jobLauncher;
}
 
Example 15
Source Project: tutorials   Source File: SpringConfig.java    License: MIT License 5 votes vote down vote up
public JobLauncher getJobLauncher() throws Exception {
    SimpleJobLauncher jobLauncher = new SimpleJobLauncher();
    // SimpleJobLauncher's methods Throws Generic Exception,
    // it would have been better to have a specific one
    jobLauncher.setJobRepository(getJobRepository());
    jobLauncher.afterPropertiesSet();
    return jobLauncher;
}
 
Example 16
Source Project: spring4-sandbox   Source File: JpaBatchConfigurer.java    License: Apache License 2.0 5 votes vote down vote up
private JobLauncher createJobLauncher() throws Exception {
	SimpleJobLauncher jobLauncher = new SimpleJobLauncher();
	jobLauncher.setJobRepository(jobRepository);
	jobLauncher.setTaskExecutor( new SimpleAsyncTaskExecutor());
	jobLauncher.afterPropertiesSet();
	return jobLauncher;
}
 
Example 17
Source Project: spring-batch-rest   Source File: AdHocBatchConfig.java    License: Apache License 2.0 4 votes vote down vote up
public JobLauncher getJobLauncher() {
    SimpleJobLauncher jobLauncher = new SimpleJobLauncher();
    jobLauncher.setJobRepository(jobRepository);
    jobLauncher.setTaskExecutor(new ConcurrentTaskExecutor(executorService));
    return jobLauncher;
}
 
Example 18
protected JobLauncher createJobLauncher() throws Exception {
    SimpleJobLauncher jobLauncher = new SimpleJobLauncher();
    jobLauncher.setJobRepository(jobRepository);
    jobLauncher.afterPropertiesSet();
    return jobLauncher;
}
 
Example 19
protected JobLauncher createJobLauncher() throws Exception {
    final SimpleJobLauncher jobLauncher = new SimpleJobLauncher();
    jobLauncher.setJobRepository(this.jobRepository);
    jobLauncher.afterPropertiesSet();
    return jobLauncher;
}