/** * Signal the {@link JobExecution} to stop. Iterates through the associated * {@link StepExecution}s, calling {@link StepExecution#setTerminateOnly()}. * */ public void stop() { for (StepExecution stepExecution : stepExecutions) { stepExecution.setTerminateOnly(); } status = BatchStatus.STOPPING; }
@Override public void beforeStep(StepExecution stepExecution) { stepExecution.setTerminateOnly(); } }
/** * Check to determine whether or not the JobExecution that is the parent of * the provided StepExecution has been interrupted. If, after synchronizing * the status with the database, the status has been updated to STOPPING, * then the job has been interrupted. * * @param stepExecution */ private void checkForInterruption(StepExecution stepExecution) { JobExecution jobExecution = stepExecution.getJobExecution(); jobExecutionDao.synchronizeStatus(jobExecution); if (jobExecution.isStopping()) { logger.info("Parent JobExecution is stopped, so passing message on to StepExecution"); stepExecution.setTerminateOnly(); } }
@Override public void execute(StepExecution stepExecution) throws JobInterruptedException, UnexpectedJobExecutionException { // This is what happens if the repository meta-data cannot be updated stepExecution.setStatus(BatchStatus.UNKNOWN); stepExecution.setTerminateOnly(); } }, new StepSupport("step2")));
@Override protected void doExecute(StepExecution context) throws Exception { context.setTerminateOnly(); super.doExecute(context); } };
rollback(stepExecution); stepExecution.upgradeStatus(BatchStatus.UNKNOWN); stepExecution.setTerminateOnly();
@Override public void execute(StepExecution stepExecution) throws JobInterruptedException { stepExecution.setStatus(BatchStatus.UNKNOWN); stepExecution.setTerminateOnly(); jobRepository.update(stepExecution); } }), "step2"));
@Override public void execute(StepExecution stepExecution) throws JobInterruptedException { stepExecution.setStatus(BatchStatus.UNKNOWN); stepExecution.setTerminateOnly(); jobRepository.update(stepExecution); } }), "step2"));
logger.error("Thread interrupted while locking for repository update"); stepExecution.setStatus(BatchStatus.STOPPED); stepExecution.setTerminateOnly(); Thread.currentThread().interrupt();
@Override protected void doExecute(StepExecution context) throws Exception { super.doExecute(context); context.setTerminateOnly(); context.setExitStatus(new ExitStatus("FUNNY")); } };
/** * Test method for {@link org.springframework.batch.core.step.ThreadStepInterruptionPolicy#checkInterrupted(StepExecution)}. * @throws Exception */ public void testCheckInterruptedComplete() throws Exception { context.setTerminateOnly(); try { policy.checkInterrupted(context); fail("Expected StepInterruptedException"); } catch (JobInterruptedException e) { // expected assertTrue(e.getMessage().indexOf("interrupt")>=0); } }
@Test public void testTerminateOnly() throws Exception { assertFalse(execution.isTerminateOnly()); execution.setTerminateOnly(); assertTrue(execution.isTerminateOnly()); }
stepExecution.setTerminateOnly(); stepExecution.addFailureException(e); throw e;
@Test public void testInterruption() throws Exception { String command = isRunningOnWindows() ? "ping 127.0.0.1" : "sleep 5"; tasklet.setCommand(command); tasklet.setTerminationCheckInterval(10); tasklet.afterPropertiesSet(); stepExecution.setTerminateOnly(); try { tasklet.execute(null, null); fail(); } catch (JobInterruptedException e) { System.out.println(e.getMessage()); assertTrue(e.getMessage().contains("Job interrupted while executing system command")); assertTrue(e.getMessage().contains(command)); } }
/** * Signal the {@link JobExecution} to stop. Iterates through the associated * {@link StepExecution}s, calling {@link StepExecution#setTerminateOnly()}. * */ public void stop() { for (StepExecution stepExecution : stepExecutions) { stepExecution.setTerminateOnly(); } status = BatchStatus.STOPPING; }
/** * Signal the {@link JobExecution} to stop. Iterates through the associated * {@link StepExecution}s, calling {@link StepExecution#setTerminateOnly()}. * */ public void stop() { for (StepExecution stepExecution : stepExecutions) { stepExecution.setTerminateOnly(); } status = BatchStatus.STOPPING; }
/** * Signal the {@link JobExecution} to stop. Iterates through the associated * {@link StepExecution}s, calling {@link StepExecution#setTerminateOnly()}. * */ public void stop() { for (StepExecution stepExecution : stepExecutions) { stepExecution.setTerminateOnly(); } status = BatchStatus.STOPPING; }
/** * Signal the {@link JobExecution} to stop. Iterates through the associated * {@link StepExecution}s, calling {@link StepExecution#setTerminateOnly()}. * */ public void stop() { for (StepExecution stepExecution : stepExecutions) { stepExecution.setTerminateOnly(); } status = BatchStatus.STOPPING; }
private void checkForInterruption(StepExecution stepExecution) { JobExecution jobExecution = stepExecution.getJobExecution(); jobExecutionDao.synchronizeStatus(jobExecution); if (jobExecution.isStopping()) { logger.info("Parent JobExecution is stopped, so passing message on to StepExecution"); stepExecution.setTerminateOnly(); } }
/** * Check to determine whether or not the JobExecution that is the parent of * the provided StepExecution has been interrupted. If, after synchronizing * the status with the database, the status has been updated to STOPPING, * then the job has been interrupted. * * @param stepExecution */ private void checkForInterruption(StepExecution stepExecution) { JobExecution jobExecution = stepExecution.getJobExecution(); jobExecutionDao.synchronizeStatus(jobExecution); if (jobExecution.isStopping()) { logger.info("Parent JobExecution is stopped, so passing message on to StepExecution"); stepExecution.setTerminateOnly(); } }