From 001226ea1dfccb714749ff25ecb0b01201eafc11 Mon Sep 17 00:00:00 2001 From: dsyer Date: Wed, 3 Jun 2009 15:57:50 +0000 Subject: [PATCH] BATCH-1268: Use System.currentTimeMillis() --- .../step/tasklet/SystemCommandTasklet.java | 36 ++++++++----------- .../SystemCommandTaskletIntegrationTests.java | 1 + 2 files changed, 15 insertions(+), 22 deletions(-) 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 141cce6d3..46bf9a4da 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 @@ -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(); } } diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/step/tasklet/SystemCommandTaskletIntegrationTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/step/tasklet/SystemCommandTaskletIntegrationTests.java index 9e7444204..37f36a512 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/step/tasklet/SystemCommandTaskletIntegrationTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/step/tasklet/SystemCommandTaskletIntegrationTests.java @@ -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);