Skip to content

Commit ba1f2a5

Browse files
committed
Check if job is stopping before checking interrupt
1 parent 425134c commit ba1f2a5

File tree

1 file changed

+12
-4
lines changed
  • spring-batch-core/src/main/java/org/springframework/batch/core/step/tasklet

1 file changed

+12
-4
lines changed

spring-batch-core/src/main/java/org/springframework/batch/core/step/tasklet/TaskletStep.java

+12-4
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import org.apache.commons.logging.LogFactory;
2020
import org.springframework.batch.core.BatchStatus;
2121
import org.springframework.batch.core.ChunkListener;
22+
import org.springframework.batch.core.JobExecution;
2223
import org.springframework.batch.core.JobInterruptedException;
2324
import org.springframework.batch.core.StepContribution;
2425
import org.springframework.batch.core.StepExecution;
@@ -71,6 +72,7 @@
7172
* @author Michael Minella
7273
* @author Will Schipp
7374
* @author Mahmoud Ben Hassine
75+
* @author Seonkyo Ok
7476
*/
7577
public class TaskletStep extends AbstractStep {
7678

@@ -238,7 +240,7 @@ protected void doExecute(StepExecution stepExecution) throws Exception {
238240
public RepeatStatus doInChunkContext(RepeatContext repeatContext, ChunkContext chunkContext)
239241
throws Exception {
240242

241-
StepExecution stepExecution = chunkContext.getStepContext().getStepExecution();
243+
final StepExecution stepExecution = chunkContext.getStepContext().getStepExecution();
242244

243245
// Before starting a new transaction, check for
244246
// interruption.
@@ -256,6 +258,12 @@ public RepeatStatus doInChunkContext(RepeatContext repeatContext, ChunkContext c
256258

257259
chunkListener.afterChunk(chunkContext);
258260

261+
final JobExecution jobExecution = stepExecution.getJobExecution();
262+
if (jobExecution.isStopping()) {
263+
logger.info("Parent JobExecution is stopped, so passing message on to StepExecution");
264+
stepExecution.setTerminateOnly();
265+
}
266+
259267
// Check for interruption after transaction as well, so that
260268
// the interrupted exception is correctly propagated up to
261269
// caller
@@ -367,7 +375,7 @@ public RepeatStatus doInTransaction(TransactionStatus status) {
367375

368376
RepeatStatus result = RepeatStatus.CONTINUABLE;
369377

370-
StepContribution contribution = stepExecution.createStepContribution();
378+
final StepContribution contribution = stepExecution.createStepContribution();
371379

372380
chunkListener.beforeChunk(chunkContext);
373381

@@ -437,7 +445,7 @@ public RepeatStatus doInTransaction(TransactionStatus status) {
437445
catch (Exception e) {
438446
// If we get to here there was a problem saving the step
439447
// execution and we have to fail.
440-
String msg = "JobRepository failure forcing rollback";
448+
final String msg = "JobRepository failure forcing rollback";
441449
logger.error(msg, e);
442450
throw new FatalStepExecutionException(msg, e);
443451
}
@@ -476,7 +484,7 @@ private void rollback(StepExecution stepExecution) {
476484
}
477485
}
478486

479-
private void copy(final StepExecution source, final StepExecution target) {
487+
private static void copy(final StepExecution source, final StepExecution target) {
480488
target.setVersion(source.getVersion());
481489
target.setWriteCount(source.getWriteCount());
482490
target.setFilterCount(source.getFilterCount());

0 commit comments

Comments
 (0)