List of usage examples for org.springframework.batch.core JobExecution setEndTime
public void setEndTime(Date endTime)
From source file:org.springframework.batch.core.test.repository.JdbcJobRepositoryTests.java
@Test public void testFindOrCreateJobConcurrentlyWhenJobAlreadyExists() throws Exception { job = new JobSupport("test-job"); job.setRestartable(true);//from ww w . j a va 2 s . c om job.setName("spam"); JobExecution execution = repository.createJobExecution(job.getName(), new JobParameters()); cacheJobIds(execution); execution.setEndTime(new Timestamp(System.currentTimeMillis())); repository.update(execution); execution.setStatus(BatchStatus.FAILED); int before = jdbcTemplate.queryForObject("SELECT COUNT(*) FROM BATCH_JOB_INSTANCE", Integer.class); assertEquals(1, before); long t0 = System.currentTimeMillis(); try { doConcurrentStart(); fail("Expected JobExecutionAlreadyRunningException"); } catch (JobExecutionAlreadyRunningException e) { // expected } long t1 = System.currentTimeMillis(); int after = jdbcTemplate.queryForObject("SELECT COUNT(*) FROM BATCH_JOB_INSTANCE", Integer.class); assertNotNull(execution.getId()); assertEquals(before, after); logger.info("Duration: " + (t1 - t0) + " - the second transaction did not block if this number is less than about 1000."); }
From source file:org.springframework.batch.sample.support.JdbcJobRepositoryTests.java
@Test public void testFindOrCreateJobConcurrentlyWhenJobAlreadyExists() throws Exception { job = new JobSupport("test-job"); job.setRestartable(true);//from w w w .j a v a2 s.c om job.setName("spam"); JobExecution execution = repository.createJobExecution(job.getName(), new JobParameters()); cacheJobIds(execution); execution.setEndTime(new Timestamp(System.currentTimeMillis())); repository.update(execution); execution.setStatus(BatchStatus.FAILED); int before = simpleJdbcTemplate.queryForInt("SELECT COUNT(*) FROM BATCH_JOB_INSTANCE"); assertEquals(1, before); long t0 = System.currentTimeMillis(); try { doConcurrentStart(); fail("Expected JobExecutionAlreadyRunningException"); } catch (JobExecutionAlreadyRunningException e) { // expected } long t1 = System.currentTimeMillis(); int after = simpleJdbcTemplate.queryForInt("SELECT COUNT(*) FROM BATCH_JOB_INSTANCE"); assertNotNull(execution.getId()); assertEquals(before, after); logger.info("Duration: " + (t1 - t0) + " - the second transaction did not block if this number is less than about 1000."); }
From source file:org.springframework.cloud.dataflow.server.batch.SimpleJobService.java
@Override public JobExecution abandon(Long jobExecutionId) throws NoSuchJobExecutionException, JobExecutionAlreadyRunningException { JobExecution jobExecution = getJobExecution(jobExecutionId); if (jobExecution.getStatus().isLessThan(BatchStatus.STOPPING)) { throw new JobExecutionAlreadyRunningException( "JobExecution is running or complete and therefore cannot be aborted"); }//from w w w. j a va2 s . co m logger.info("Aborting job execution: " + jobExecution); Collection<String> jsrJobNames = getJsrJobNames(); JobInstance jobInstance = jobExecution.getJobInstance(); if (jsrJobOperator != null && jsrJobNames.contains(jobInstance.getJobName())) { jsrJobOperator.abandon(jobExecutionId); jobExecution = getJobExecution(jobExecutionId); } else { jobExecution.upgradeStatus(BatchStatus.ABANDONED); jobExecution.setEndTime(new Date()); jobRepository.update(jobExecution); } return jobExecution; }