BATCH-1268: Use System.currentTimeMillis()

This commit is contained in:
dsyer
2009-06-03 15:57:50 +00:00
parent 132e29f37b
commit 001226ea1d
2 changed files with 15 additions and 22 deletions

View File

@@ -33,7 +33,6 @@ import org.springframework.beans.factory.InitializingBean;
import org.springframework.core.task.SimpleAsyncTaskExecutor;
import org.springframework.core.task.TaskExecutor;
import org.springframework.util.Assert;
import org.springframework.util.StopWatch;
/**
* {@link Tasklet} that executes a system command.
@@ -93,31 +92,24 @@ public class SystemCommandTasklet extends StepExecutionListenerSupport implement
});
StopWatch stopWatch = new StopWatch();
stopWatch.start();
long t0 = System.currentTimeMillis();
taskExecutor.execute(systemCommandTask);
try {
while (true) {
Thread.sleep(checkInterval);
if (systemCommandTask.isDone()) {
contribution.setExitStatus(systemProcessExitCodeMapper.getExitStatus(systemCommandTask.get()));
return RepeatStatus.FINISHED;
}
else if (stopWatch.getTotalTimeMillis() > timeout) {
systemCommandTask.cancel(interruptOnCancel);
throw new SystemCommandException("Execution of system command did not finish within the timeout");
}
else if (execution.isTerminateOnly()) {
systemCommandTask.cancel(interruptOnCancel);
throw new JobInterruptedException("Job interrupted while executing system command '" + command
+ "'");
}
while (true) {
Thread.sleep(checkInterval);
if (systemCommandTask.isDone()) {
contribution.setExitStatus(systemProcessExitCodeMapper.getExitStatus(systemCommandTask.get()));
return RepeatStatus.FINISHED;
}
else if (System.currentTimeMillis() - t0 > timeout) {
systemCommandTask.cancel(interruptOnCancel);
throw new SystemCommandException("Execution of system command did not finish within the timeout");
}
else if (execution.isTerminateOnly()) {
systemCommandTask.cancel(interruptOnCancel);
throw new JobInterruptedException("Job interrupted while executing system command '" + command + "'");
}
}
finally {
stopWatch.stop();
}
}

View File

@@ -70,6 +70,7 @@ public class SystemCommandTaskletIntegrationTests {
public void testExecuteFailure() throws Exception {
String command = "java org.springframework.batch.sample.tasklet.UnknownClass";
tasklet.setCommand(command);
tasklet.setTimeout(200L);
tasklet.afterPropertiesSet();
log.info("Executing command: " + command);