当前位置: 首页>>代码示例>>Java>>正文


Java JobParametersBuilder类代码示例

本文整理汇总了Java中org.springframework.batch.core.JobParametersBuilder的典型用法代码示例。如果您正苦于以下问题:Java JobParametersBuilder类的具体用法?Java JobParametersBuilder怎么用?Java JobParametersBuilder使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


JobParametersBuilder类属于org.springframework.batch.core包,在下文中一共展示了JobParametersBuilder类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: main

import org.springframework.batch.core.JobParametersBuilder; //导入依赖的package包/类
public static void main(String[] args) {

		String[] springConfig = { "spring/batch/jobs/job-config.xml" };

		@SuppressWarnings("resource")
		ApplicationContext context = new ClassPathXmlApplicationContext(springConfig);

		JobLauncher jobLauncher = (JobLauncher) context.getBean("jobLauncher");
		Job job = (Job) context.getBean("chunkJob");

		try {
			JobParameters jobParameters = new JobParametersBuilder().addLong("time",System.currentTimeMillis()).toJobParameters();
			JobExecution execution = jobLauncher.run(job, jobParameters);
			System.out.println("Exit Status : " + execution.getStatus());
			System.out.println("Exit Status : " + execution.getAllFailureExceptions());

		} catch (Exception e) {
			e.printStackTrace();
		}

		System.out.println("Done");

	}
 
开发者ID:maldiny,项目名称:Spring-Batch-en-Castellano,代码行数:24,代码来源:Main.java

示例2: main

import org.springframework.batch.core.JobParametersBuilder; //导入依赖的package包/类
public static void main(String[] args) {

		String[] springConfig = { "spring/batch/jobs/job-config.xml" };

		@SuppressWarnings("resource")
		ApplicationContext context = new ClassPathXmlApplicationContext(springConfig);

		JobLauncher jobLauncher = (JobLauncher) context.getBean("jobLauncher");
		Job job = (Job) context.getBean("taskletJob");

		try {
			JobParameters jobParameters = new JobParametersBuilder().addLong("time",System.currentTimeMillis()).toJobParameters();
			JobExecution execution = jobLauncher.run(job, jobParameters);
			System.out.println("Exit Status : " + execution.getStatus());
			System.out.println("Exit Status : " + execution.getAllFailureExceptions());

		} catch (Exception e) {
			e.printStackTrace();
		}

		System.out.println("Done");

	}
 
开发者ID:maldiny,项目名称:Spring-Batch-en-Castellano,代码行数:24,代码来源:Main.java

示例3: runner

import org.springframework.batch.core.JobParametersBuilder; //导入依赖的package包/类
CommandLineRunner runner(JobLauncher launcher,
                         Job job,
                         @Value("${file}") File in,
                         JdbcTemplate jdbcTemplate) {
    return args -> {

        JobExecution execution = launcher.run(job,
                new JobParametersBuilder()
                        .addString("file", in.getAbsolutePath())
                        .toJobParameters());

        System.out.println("execution status: " + execution.getExitStatus().toString());

        List<Person> personList = jdbcTemplate.query("select * from PEOPLE", (resultSet, i) -> new Person(resultSet.getString("first"),
                resultSet.getString("last"),
                resultSet.getString("email")));

        personList.forEach(System.out::println);

    };

}
 
开发者ID:livelessons-spring,项目名称:building-microservices,代码行数:23,代码来源:BatchConfiguration.java

示例4: runDemoJob

import org.springframework.batch.core.JobParametersBuilder; //导入依赖的package包/类
@Scheduled(fixedDelayString = "${demo.job.fixed.delay.seconds:60}000")
public void runDemoJob() {

    SimpleDateFormat format = new SimpleDateFormat("M-dd-yy hh:mm:ss");
    String startDateTime = format.format(new Date());

    JobParameters jobParameters =
            new JobParametersBuilder()
                    .addLong("iterations", iterations)
                    .addString("username", username)
                    .addLong("time", System.currentTimeMillis()).toJobParameters();

    try {
        logger.info("");
        logger.info("STARTING BATCH JOB AT " + startDateTime);
        JobExecution execution = jobLauncher.run(demoJob, jobParameters);
        logger.info("JOB STATUS : " + execution.getStatus());
    } catch (Exception e) {
        e.printStackTrace();
        logger.info("JOB FAILED!!!");
    }

}
 
开发者ID:mintster,项目名称:nixmash-blog,代码行数:24,代码来源:DemoJobRunner.java

示例5: start

import org.springframework.batch.core.JobParametersBuilder; //导入依赖的package包/类
public void start() throws IOException, InterruptedException {
	List<JobExecution> jobExecutions = new ArrayList<>();
	// launch jobs
	jobExecutions.addAll(IntStream.range(0, this.cardinality).mapToObj(i -> {
		Job analysisJob = this.jobFactory.get();
		JobParametersBuilder jobParametersBuilder = new JobParametersBuilder();
		jobParametersBuilder.addString("id", analysisJob.getName() + "-" + i, true);
		try {
			return this.jobLauncher.run(analysisJob, jobParametersBuilder.toJobParameters());
		} catch (JobExecutionAlreadyRunningException | JobRestartException | JobInstanceAlreadyCompleteException
				| JobParametersInvalidException exception) {
			throw new RuntimeException(exception);
		}
	}).collect(Collectors.toList()));
	// wait for termination
	while (jobExecutions.stream().anyMatch(jobExecution -> jobExecution.getStatus().isRunning())) {
		Thread.sleep(1000);
	}
}
 
开发者ID:maenu,项目名称:kowalski,代码行数:20,代码来源:Application.java

示例6: retryFailedExecutionWithNonIdentifyingParameters

import org.springframework.batch.core.JobParametersBuilder; //导入依赖的package包/类
@Test
public void retryFailedExecutionWithNonIdentifyingParameters() throws Exception {
	this.job = this.jobs.get("job")
			.start(this.steps.get("step").tasklet(new Tasklet() {
				@Override
				public RepeatStatus execute(StepContribution contribution,
						ChunkContext chunkContext) throws Exception {
					throw new RuntimeException("Planned");
				}
			}).build()).incrementer(new RunIdIncrementer()).build();
	JobParameters jobParameters = new JobParametersBuilder().addLong("id", 1L, false)
			.addLong("foo", 2L, false).toJobParameters();
	this.runner.execute(this.job, jobParameters);
	this.runner.execute(this.job, jobParameters);
	assertThat(this.jobExplorer.getJobInstances("job", 0, 100)).hasSize(1);
}
 
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:17,代码来源:JobLauncherCommandLineRunnerTests.java

示例7: main

import org.springframework.batch.core.JobParametersBuilder; //导入依赖的package包/类
public static void main(String[] args) {

		String[] springConfig = { "spring/batch/jobs/job-config.xml" };

		@SuppressWarnings("resource")
		ApplicationContext context = new ClassPathXmlApplicationContext(springConfig);

		JobLauncher jobLauncher = (JobLauncher) context.getBean("jobLauncher");
		Job job = (Job) context.getBean("multiResourceItemReaderJob");

		try {
			JobParameters jobParameters = new JobParametersBuilder().addLong("time",System.currentTimeMillis()).toJobParameters();
			JobExecution execution = jobLauncher.run(job, jobParameters);
			System.out.println("Exit Status : " + execution.getStatus());
			System.out.println("Exit Status : " + execution.getAllFailureExceptions());

		} catch (Exception e) {
			e.printStackTrace();
		}

		System.out.println("Done");

	}
 
开发者ID:maldiny,项目名称:Spring-Batch-en-Castellano,代码行数:24,代码来源:Main.java

示例8: main

import org.springframework.batch.core.JobParametersBuilder; //导入依赖的package包/类
public static void main(String[] args) {

		String[] springConfig = { "spring/batch/jobs/job-config.xml" };

		@SuppressWarnings("resource")
		ApplicationContext context = new ClassPathXmlApplicationContext(springConfig);

		JobLauncher jobLauncher = (JobLauncher) context.getBean("jobLauncher");
		Job job = (Job) context.getBean("customReaderWriterProcesorJob");

		try {
			JobParameters jobParameters = new JobParametersBuilder().addLong("time",System.currentTimeMillis()).toJobParameters();
			JobExecution execution = jobLauncher.run(job, jobParameters);
			System.out.println("Exit Status : " + execution.getStatus());
			System.out.println("Exit Status : " + execution.getAllFailureExceptions());

		} catch (Exception e) {
			e.printStackTrace();
		}
		
		System.out.println("Done");

	}
 
开发者ID:maldiny,项目名称:Spring-Batch-en-Castellano,代码行数:24,代码来源:Main.java

示例9: main

import org.springframework.batch.core.JobParametersBuilder; //导入依赖的package包/类
public static void main(String[] args) {

		String[] springConfig = { "spring/batch/jobs/job-config.xml" };

		@SuppressWarnings("resource")
		ApplicationContext context = new ClassPathXmlApplicationContext(springConfig);

		JobLauncher jobLauncher = (JobLauncher) context.getBean("jobLauncher");
		Job job = (Job) context.getBean("customListeners");

		try {
			JobParameters jobParameters = new JobParametersBuilder().addLong("time",System.currentTimeMillis()).toJobParameters();
			JobExecution execution = jobLauncher.run(job, jobParameters);
			System.out.println("Exit Status : " + execution.getStatus());
			System.out.println("Exit Status : " + execution.getAllFailureExceptions());

		} catch (Exception e) {
			e.printStackTrace();
		}
		
		System.out.println("Done");

	}
 
开发者ID:maldiny,项目名称:Spring-Batch-en-Castellano,代码行数:24,代码来源:Main.java

示例10: main

import org.springframework.batch.core.JobParametersBuilder; //导入依赖的package包/类
public static void main(String[] args) {

		String[] springConfig = { "spring/batch/jobs/job-config.xml" };

		@SuppressWarnings("resource")
		ApplicationContext context = new ClassPathXmlApplicationContext(springConfig);

		JobLauncher jobLauncher = (JobLauncher) context.getBean("jobLauncher");
		Job job = (Job) context.getBean("flatFileItemWriterJob");

		try {
			JobParameters jobParameters = new JobParametersBuilder().addLong("time",System.currentTimeMillis()).toJobParameters();
			JobExecution execution = jobLauncher.run(job, jobParameters);
			System.out.println("Exit Status : " + execution.getStatus());
			System.out.println("Exit Status : " + execution.getAllFailureExceptions());

		} catch (Exception e) {
			e.printStackTrace();
		}

		System.out.println("Done");

	}
 
开发者ID:maldiny,项目名称:Spring-Batch-en-Castellano,代码行数:24,代码来源:Main.java

示例11: main

import org.springframework.batch.core.JobParametersBuilder; //导入依赖的package包/类
public static void main(String[] args) {

		String[] springConfig = { "spring/batch/jobs/job-config.xml" };

		@SuppressWarnings("resource")
		ApplicationContext context = new ClassPathXmlApplicationContext(springConfig);

		JobLauncher jobLauncher = (JobLauncher) context.getBean("jobLauncher");
		Job job = (Job) context.getBean("parallelStepsJob");

		try {
			JobParameters jobParameters = new JobParametersBuilder().addLong("time",System.currentTimeMillis()).toJobParameters();
			JobExecution execution = jobLauncher.run(job, jobParameters);
			System.out.println("Exit Status : " + execution.getStatus());
			System.out.println("Exit Status : " + execution.getAllFailureExceptions());

		} catch (Exception e) {
			e.printStackTrace();
		}

		System.out.println("Done");

	}
 
开发者ID:maldiny,项目名称:Spring-Batch-en-Castellano,代码行数:24,代码来源:Main.java

示例12: main

import org.springframework.batch.core.JobParametersBuilder; //导入依赖的package包/类
public static void main(String[] args) {

		String[] springConfig = { "spring/batch/jobs/job-config.xml" };

		@SuppressWarnings("resource")
		ApplicationContext context = new ClassPathXmlApplicationContext(springConfig);

		JobLauncher jobLauncher = (JobLauncher) context.getBean("jobLauncher");
		Job job = (Job) context.getBean("secuentialControlFlow");

		try {
			JobParameters jobParameters = new JobParametersBuilder().addLong("time",System.currentTimeMillis()).toJobParameters();
			JobExecution execution = jobLauncher.run(job, jobParameters);
			System.out.println("Exit Status : " + execution.getStatus());
			System.out.println("Exit Status : " + execution.getAllFailureExceptions());

		} catch (Exception e) {
			e.printStackTrace();
		}
		
		System.out.println("Done");

	}
 
开发者ID:maldiny,项目名称:Spring-Batch-en-Castellano,代码行数:24,代码来源:Main.java

示例13: main

import org.springframework.batch.core.JobParametersBuilder; //导入依赖的package包/类
public static void main(String[] args) {

		String[] springConfig = { "spring/batch/jobs/job-config.xml" };

		@SuppressWarnings("resource")
		ApplicationContext context = new ClassPathXmlApplicationContext(springConfig);

		JobLauncher jobLauncher = (JobLauncher) context.getBean("jobLauncher");
		Job job = (Job) context.getBean("xmlReadersWritersJob");

		try {
			JobParameters jobParameters = new JobParametersBuilder().addLong("time",System.currentTimeMillis()).toJobParameters();
			JobExecution execution = jobLauncher.run(job, jobParameters);
			System.out.println("Exit Status : " + execution.getStatus());
			System.out.println("Exit Status : " + execution.getAllFailureExceptions());

		} catch (Exception e) {
			e.printStackTrace();
		}

		System.out.println("Done");

	}
 
开发者ID:maldiny,项目名称:Spring-Batch-en-Castellano,代码行数:24,代码来源:Main.java

示例14: prepareJobParameters

import org.springframework.batch.core.JobParametersBuilder; //导入依赖的package包/类
/**
 * Helper method converting the Camel message headers into the Spring Batch parameters map. Date, Long and Double
 * header values are converted to the appropriate types. All the other header values are converted to string
 * representation.
 *
 * @param headers Camel message header to be converted
 * @return Camel message headers converted into the Spring Batch parameters map
 */
protected JobParameters prepareJobParameters(Map<String, Object> headers) {
    JobParametersBuilder parametersBuilder = new JobParametersBuilder();
    for (Map.Entry<String, Object> headerEntry : headers.entrySet()) {
        String headerKey = headerEntry.getKey();
        Object headerValue = headerEntry.getValue();
        if (headerValue instanceof Date) {
            parametersBuilder.addDate(headerKey, (Date) headerValue);
        } else if (headerValue instanceof Long) {
            parametersBuilder.addLong(headerKey, (Long) headerValue);
        } else if (headerValue instanceof Double) {
            parametersBuilder.addDouble(headerKey, (Double) headerValue);
        } else if (headerValue != null) {
            parametersBuilder.addString(headerKey, headerValue.toString());
        } else {
            // if the value is null we just put String with null value here to avoid the NPE
            parametersBuilder.addString(headerKey, null);
        }
    }
    JobParameters jobParameters = parametersBuilder.toJobParameters();
    log.debug("Prepared parameters for Spring Batch job: {}", jobParameters);
    return jobParameters;
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:31,代码来源:SpringBatchProducer.java

示例15: launch

import org.springframework.batch.core.JobParametersBuilder; //导入依赖的package包/类
@RequestMapping("/launch")
public String launch() throws JobExecutionAlreadyRunningException,
        JobRestartException, JobInstanceAlreadyCompleteException,
        JobParametersInvalidException {

    //JobParametersの内容を変更しないと同一のジョブ実行と思われるっぽい。
    //同一のジョブ実行だと思われたら二回目からは実行されない。
    //(一回目の実行が既に完了しているので)
    //とりあえずIDっぽいものを持たせて実行の要求の度にインクリメントすることで
    //何度も実行できるようになった。
    //cf. JobParametersIncrementer
    JobParameters jobParameters = new JobParametersBuilder().addLong(
            "simpleBatchId", idGenerator.getAndIncrement())
            .toJobParameters();
    JobExecution execution = launcher.run(job, jobParameters);

    return execution.toString();
}
 
开发者ID:backpaper0,项目名称:spring-boot-sandbox,代码行数:19,代码来源:BatchLauncherController.java


注:本文中的org.springframework.batch.core.JobParametersBuilder类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。