19
19
import org .apache .commons .logging .LogFactory ;
20
20
import org .springframework .batch .core .BatchStatus ;
21
21
import org .springframework .batch .core .ChunkListener ;
22
+ import org .springframework .batch .core .JobExecution ;
22
23
import org .springframework .batch .core .JobInterruptedException ;
23
24
import org .springframework .batch .core .StepContribution ;
24
25
import org .springframework .batch .core .StepExecution ;
71
72
* @author Michael Minella
72
73
* @author Will Schipp
73
74
* @author Mahmoud Ben Hassine
75
+ * @author Seonkyo Ok
74
76
*/
75
77
public class TaskletStep extends AbstractStep {
76
78
@@ -238,7 +240,7 @@ protected void doExecute(StepExecution stepExecution) throws Exception {
238
240
public RepeatStatus doInChunkContext (RepeatContext repeatContext , ChunkContext chunkContext )
239
241
throws Exception {
240
242
241
- StepExecution stepExecution = chunkContext .getStepContext ().getStepExecution ();
243
+ final StepExecution stepExecution = chunkContext .getStepContext ().getStepExecution ();
242
244
243
245
// Before starting a new transaction, check for
244
246
// interruption.
@@ -256,6 +258,12 @@ public RepeatStatus doInChunkContext(RepeatContext repeatContext, ChunkContext c
256
258
257
259
chunkListener .afterChunk (chunkContext );
258
260
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
+
259
267
// Check for interruption after transaction as well, so that
260
268
// the interrupted exception is correctly propagated up to
261
269
// caller
@@ -367,7 +375,7 @@ public RepeatStatus doInTransaction(TransactionStatus status) {
367
375
368
376
RepeatStatus result = RepeatStatus .CONTINUABLE ;
369
377
370
- StepContribution contribution = stepExecution .createStepContribution ();
378
+ final StepContribution contribution = stepExecution .createStepContribution ();
371
379
372
380
chunkListener .beforeChunk (chunkContext );
373
381
@@ -437,7 +445,7 @@ public RepeatStatus doInTransaction(TransactionStatus status) {
437
445
catch (Exception e ) {
438
446
// If we get to here there was a problem saving the step
439
447
// execution and we have to fail.
440
- String msg = "JobRepository failure forcing rollback" ;
448
+ final String msg = "JobRepository failure forcing rollback" ;
441
449
logger .error (msg , e );
442
450
throw new FatalStepExecutionException (msg , e );
443
451
}
@@ -476,7 +484,7 @@ private void rollback(StepExecution stepExecution) {
476
484
}
477
485
}
478
486
479
- private void copy (final StepExecution source , final StepExecution target ) {
487
+ private static void copy (final StepExecution source , final StepExecution target ) {
480
488
target .setVersion (source .getVersion ());
481
489
target .setWriteCount (source .getWriteCount ());
482
490
target .setFilterCount (source .getFilterCount ());
0 commit comments