Update stopped flag to volitile in SystemCommandTasklet

The SystemCommandTasklet checks a flag to determine if another thread
has requested that it be stopped.  Since this flag will be set via
another thread than the executing thread, it needs to be declared
volitile so that it's state is propigated across threads correctly.  The
documentation for StoppableTasklet has also been upadted to call out
that scenario.

This commit addresses Jira BATCH-2271
This commit is contained in:
Michael Minella
2014-09-22 15:39:17 -05:00
parent 1857743712
commit aee9dc2f6f
2 changed files with 9 additions and 6 deletions

View File

@@ -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

View File

@@ -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