I use this code to list and complete tasks
private String jobName = ""; private JobLauncher jobLauncher = null; private String selectedJob; private String statusJob = "Exit Status : "; private Job job; ApplicationContext context; private String[] lstJobs; public ExecuteJobBean() { this.context = ApplicationContextProvider.getApplicationContext(); this.lstJobs = context.getBeanNamesForType(Job.class); if (jobLauncher == null) jobLauncher = (JobLauncher) context.getBean("jobLauncher"); } public void executeJob() { setJob((Job) context.getBean(this.selectedJob)); try { statusJob = "Exit Status : "; JobParameters jobParameters = new JobParametersBuilder().addLong("time", System.currentTimeMillis()).toJobParameters(); JobExecution execution = jobLauncher.run(getJob(), jobParameters); this.statusJob = execution.getStatus() + ", "; } catch (Exception e) { e.printStackTrace(); this.statusJob = "Error, " + e.getMessage(); } this.statusJob += " Done!!"; }
ZaoTaoBao
source share