本文整理汇总了Java中org.springframework.batch.core.Job类的典型用法代码示例。如果您正苦于以下问题:Java Job类的具体用法?Java Job怎么用?Java Job使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Job类属于org.springframework.batch.core包,在下文中一共展示了Job类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: main
import org.springframework.batch.core.Job; //导入依赖的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.Job; //导入依赖的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: personEtl
import org.springframework.batch.core.Job; //导入依赖的package包/类
@Bean
Job personEtl(JobBuilderFactory jobBuilderFactory,
StepBuilderFactory stepBuilderFactory,
FlatFileItemReader<Person> reader,
JdbcBatchItemWriter<Person> writer
) {
Step step = stepBuilderFactory.get("file-to-database")
.<Person, Person>chunk(5)
.reader(reader)
.writer(writer)
.build();
return jobBuilderFactory.get("etl")
.start(step)
.build();
}
示例4: runner
import org.springframework.batch.core.Job; //导入依赖的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);
};
}
示例5: testWriteTaxonFile
import org.springframework.batch.core.Job; //导入依赖的package包/类
/**
* @throws Exception
*/
@Test
public void testWriteTaxonFile() throws Exception {
Map<String, JobParameter> parameters = new HashMap<String, JobParameter>();
parameters.put("query", new JobParameter(""));
parameters.put("selected.facets", new JobParameter("taxon.family_ss=Araceae"));
parameters.put("download.taxon", new JobParameter(toParameter(DarwinCorePropertyMap.getConceptTerms(DwcTerm.Taxon))));
parameters.put("download.file", new JobParameter(UUID.randomUUID().toString() + ".txt"));
parameters.put("download.limit", new JobParameter(new Integer(Integer.MAX_VALUE).toString()));
parameters.put("download.fieldsTerminatedBy", new JobParameter("\t"));
parameters.put("download.fieldsEnclosedBy", new JobParameter("\""));
parameters.put("download.format", new JobParameter("taxon"));
JobParameters jobParameters = new JobParameters(parameters);
Job archiveCreatorJob = jobLocator.getJob("FlatFileCreation");
assertNotNull("flatFileCreatorJob must exist", archiveCreatorJob);
JobExecution jobExecution = jobLauncher.run(archiveCreatorJob,
jobParameters);
assertEquals("The Job should be sucessful", ExitStatus.COMPLETED, jobExecution.getExitStatus());
}
示例6: testCreateGenericArchive
import org.springframework.batch.core.Job; //导入依赖的package包/类
@Test
public void testCreateGenericArchive() throws NoSuchJobException,
JobExecutionAlreadyRunningException, JobRestartException,
JobInstanceAlreadyCompleteException, JobParametersInvalidException, IOException {
Map<String, JobParameter> parameters =
new HashMap<String, JobParameter>();
JobParameters jobParameters = new JobParameters(parameters);
Job palmwebArchive = jobLocator.getJob("PalmWeb");
assertNotNull("Palmweb must not be null", palmwebArchive);
JobExecution jobExecution = jobLauncher.run(palmwebArchive, jobParameters);
assertEquals("The job should complete successfully",jobExecution.getExitStatus().getExitCode(),"COMPLETED");
for (StepExecution stepExecution : jobExecution.getStepExecutions()) {
logger.info(stepExecution.getStepName() + " "
+ stepExecution.getReadCount() + " "
+ stepExecution.getFilterCount() + " "
+ stepExecution.getWriteCount() + " " + stepExecution.getCommitCount());
}
}
示例7: getObject
import org.springframework.batch.core.Job; //导入依赖的package包/类
@Override
public Job getObject() throws Exception {
ComposedRunnerVisitor composedRunnerVisitor = new ComposedRunnerVisitor();
TaskParser taskParser = new TaskParser("composed-task-runner",
this.dsl,false,true);
taskParser.parse().accept(composedRunnerVisitor);
this.visitorDeque = composedRunnerVisitor.getFlow();
FlowJobBuilder builder = this.jobBuilderFactory
.get(this.taskNameResolver.getTaskName())
.start(this.flowBuilder
.start(createFlow())
.end())
.end();
if(this.incrementInstanceEnabled) {
builder.incrementer(new RunIdIncrementer());
}
return builder.build();
}
开发者ID:spring-cloud-task-app-starters,项目名称:composed-task-runner,代码行数:22,代码来源:ComposedRunnerJobFactory.java
示例8: start
import org.springframework.batch.core.Job; //导入依赖的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);
}
}
示例9: registerJob
import org.springframework.batch.core.Job; //导入依赖的package包/类
private Map<String, Object> registerJob(String jobName) throws DuplicateJobException {
String taskId = jobKeyMap.get(JoinCode.getTaskCode(jobName)).getTaskId();
TaskDefineEntity tm = taskDefineMap.get(taskId);
Job job = taskletConfig.job(conf, jobName, tm.getTaskType(), tm.getScriptFile());
ReferenceJobFactory regJob = new ReferenceJobFactory(job);
try {
jobRegistry.register(regJob);
} catch (DuplicateJobException e) {
jobRegistry.unregister(jobName);
jobRegistry.register(regJob);
}
logger.debug("register job,job name is :{}", jobName);
Map<String, Object> map = new HashMap<>();
map.put("jobName", jobName);
map.put("jobLauncher", jobLauncher);
map.put("jobRegistry", jobRegistry);
map.put("jobKeyStatusService", jobKeyStatusService);
map.put("argumentService", argumentService);
return map;
}
示例10: executeRegisteredJobs
import org.springframework.batch.core.Job; //导入依赖的package包/类
private void executeRegisteredJobs(JobParameters jobParameters)
throws JobExecutionException {
if (this.jobRegistry != null && StringUtils.hasText(this.jobNames)) {
String[] jobsToRun = this.jobNames.split(",");
for (String jobName : jobsToRun) {
try {
Job job = this.jobRegistry.getJob(jobName);
if (this.jobs.contains(job)) {
continue;
}
execute(job, jobParameters);
}
catch (NoSuchJobException ex) {
logger.debug("No job found in registry for job name: " + jobName);
continue;
}
}
}
}
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:20,代码来源:JobLauncherCommandLineRunner.java
示例11: discreteJob
import org.springframework.batch.core.Job; //导入依赖的package包/类
@Bean
public Job discreteJob() {
AbstractJob job = new AbstractJob("discreteRegisteredJob") {
@Override
public Collection<String> getStepNames() {
return Collections.emptySet();
}
@Override
public Step getStep(String stepName) {
return null;
}
@Override
protected void doExecute(JobExecution execution)
throws JobExecutionException {
execution.setStatus(BatchStatus.COMPLETED);
}
};
job.setJobRepository(this.jobRepository);
return job;
}
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:24,代码来源:BatchAutoConfigurationTests.java
示例12: main
import org.springframework.batch.core.Job; //导入依赖的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");
}
示例13: main
import org.springframework.batch.core.Job; //导入依赖的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");
}
示例14: main
import org.springframework.batch.core.Job; //导入依赖的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");
}
示例15: main
import org.springframework.batch.core.Job; //导入依赖的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");
}