按照标题,我有一个使用 Spring Batch 在后端运行的服务。
我的服务:
@Service
publlic class TestBatch {
public void testDelay(String jobID) {
// TODO Auto-generated method stub
try {
for(int i=0; i< 1000; i++) {
Thread.sleep(1000);
System.out.println(jobID + " is running");
}
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
我的小任务:
public class TestTasklet implement Tasklet {
@Resource
private TestBatch testBatch ;
@Override
public RepeatStatus execute(StepContribution contribution, ChunkContext chunkContext) throws Exception {
testBatch.testDelay("Test01"); // Param to show in cololog
return RepeatStatus.FINISHED;
}
}
我试图停止工作:
@Service
public class JobService {
@Autowired
private SimpleJobOperator simpleJobOperator;
@Autowired
private JobExplorer jobs;
public void stopJob(String jobid) {
simpleJobOperator.stop(jobid);// Using job operator
JobExecution jobExecution = jobs.getJobExecution(jobid); // Using job execution
jobExecution.stop();
}
}
作业已停止,但在我的控制台中仍然输出文本:
Test01 is running
Test01 is running
Test01 is running
...
我不知道如何停止TestBatch
-testDelay()
工作停止时的方法。我该怎么做?