diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/step/tasklet/StoppableTasklet.java b/spring-batch-core/src/main/java/org/springframework/batch/core/step/tasklet/StoppableTasklet.java index 21f357a93..362866c56 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/step/tasklet/StoppableTasklet.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/step/tasklet/StoppableTasklet.java @@ -23,7 +23,10 @@ import org.springframework.batch.core.launch.JobOperator; * as to how the stop will behave. The only guarantee provided by the * framework is that a call to {@link JobOperator#stop(long)} will * attempt to call the stop method on any currently running - * StoppableTasklet. + * StoppableTasklet. The call to {@link StoppableTasklet#stop()} will + * be from a thread other than the thread executing {@link org.springframework.batch.core.step.tasklet.Tasklet#execute(org.springframework.batch.core.StepContribution, org.springframework.batch.core.scope.context.ChunkContext)} + * so the appropriate thread safety and visibility controls should be + * put in place. * * @author Will Schipp * @since 3.0 diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/step/tasklet/SystemCommandTasklet.java b/spring-batch-core/src/main/java/org/springframework/batch/core/step/tasklet/SystemCommandTasklet.java index ba437cc47..1fd71b975 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/step/tasklet/SystemCommandTasklet.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/step/tasklet/SystemCommandTasklet.java @@ -16,10 +16,6 @@ package org.springframework.batch.core.step.tasklet; -import java.io.File; -import java.util.concurrent.Callable; -import java.util.concurrent.FutureTask; - import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.springframework.batch.core.ExitStatus; @@ -34,6 +30,10 @@ import org.springframework.core.task.SimpleAsyncTaskExecutor; import org.springframework.core.task.TaskExecutor; import org.springframework.util.Assert; +import java.io.File; +import java.util.concurrent.Callable; +import java.util.concurrent.FutureTask; + /** * {@link Tasklet} that executes a system command. * @@ -78,7 +78,7 @@ public class SystemCommandTasklet extends StepExecutionListenerSupport implement private boolean interruptOnCancel = false; - private boolean stopped = false; + private volatile boolean stopped = false; /** * Execute system command and map its exit code to {@link ExitStatus} using