本文整理汇总了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");
}
示例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");
}
示例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);
};
}
示例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!!!");
}
}
示例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);
}
}
示例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");
}
示例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");
}
示例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");
}
示例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");
}
示例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");
}
示例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");
}
示例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");
}
示例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;
}
示例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();
}