Spring批处理:不重新启动已完成的步骤

Spring批处理:不重新启动已完成的步骤,spring,spring-batch,Spring,Spring Batch,在Spring批处理中,当重新启动作业时,不应重新启动已完成的步骤。但我的情况并非如此 在下面的代码段中,myTasklet2依赖于myTasklet1。这两个和myTasklet3并行运行。在第一次运行中,myTasklet1失败,因此myTasklet2也失败。但是myTasklet3成功了。当我再次运行作业时,它应该只运行myTasklet1和myTasklet2。但它也运行myTasklet3 有人能帮我弄清楚我是否犯了什么错误吗 <beans xmlns="http://www.

在Spring批处理中,当重新启动作业时,不应重新启动已完成的步骤。但我的情况并非如此

在下面的代码段中,myTasklet2依赖于myTasklet1。这两个和myTasklet3并行运行。在第一次运行中,myTasklet1失败,因此myTasklet2也失败。但是myTasklet3成功了。当我再次运行作业时,它应该只运行myTasklet1和myTasklet2。但它也运行myTasklet3

有人能帮我弄清楚我是否犯了什么错误吗

<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:batch="http://www.springframework.org/schema/batch" 
xmlns:task="http://www.springframework.org/schema/task"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/batch
    http://www.springframework.org/schema/batch/spring-batch-2.2.xsd
    http://www.springframework.org/schema/beans 
    http://www.springframework.org/schema/beans/spring-beans-3.2.xsd">


<bean id="myTasklet1" class="com.flow.test.MyTasklet1" />  

<bean id="myTasklet2" class="com.flow.test.MyTasklet2" />  

<bean id="myTasklet3" class="com.flow.test.MyTasklet3" />  

<!-- bean id="taskExecutor" class="org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor">
    <property name="corePoolSize" value="25" />                  
    <property name="maxPoolSize" value="25" />        
</bean-->

<bean id="taskExecutor" class="org.springframework.core.task.SimpleAsyncTaskExecutor"/>

    <batch:job id="myCustomJob1" restartable="false">  
         <batch:step id="step1" next="step2">  
              <batch:tasklet transaction-manager="transactionManager" ref="myTasklet1" allow-start-if-complete="false">  
              </batch:tasklet>  
         </batch:step>  
         <batch:step id="step2">  
              <batch:tasklet transaction-manager="transactionManager" ref="myTasklet2" allow-start-if-complete="false">  
              </batch:tasklet>  
         </batch:step>  
    </batch:job>    
    <batch:job id="myCustomJob2" restartable="false">  
         <batch:step id="step3">  
              <batch:tasklet transaction-manager="transactionManager" ref="myTasklet3" allow-start-if-complete="false">  
              </batch:tasklet>  
         </batch:step>  
    </batch:job>    

<batch:job id="myCustomJob" job-repository="jobRepository" parent="simpleJob" restartable="false">  
    <batch:split id="preprocessingStep" task-executor="taskExecutor">
        <batch:flow>
            <batch:step id="stepflow1" allow-start-if-complete="false">
                <batch:job ref="myCustomJob1" />
            </batch:step>
        </batch:flow>
        <batch:flow>
            <batch:step id="stepflow2" allow-start-if-complete="false">
                <batch:job ref="myCustomJob2" />
            </batch:step>
        </batch:flow>
    </batch:split>
</batch:job>     



这在我看来并不正确:您的
myCustomJob
被声明为
restartable=false
,这意味着在重新启动同一个作业实例时,它应该抛出异常。然而从你的问题来看,你的工作似乎可以重新开始。我怀疑你在启动工作时是否传递了相同的工作参数。阿德里安,有什么具体的方法传递工作参数吗?在MyTasklet1类中,我正在检查标记文件。在第一次运行中,文件不存在,因此该步骤失败。然后我放置文件并再次运行作业。在这个测试中,我再次运行同一个作业,除了标记文件外,没有做任何更改。无论何时启动作业,都应该告诉joblauncher作业名称和参数。检查spring批处理文档,这些概念应该出现在前几章中,这在我看来并不正确:您的
myCustomJob
声明为
restartable=false
,这意味着在重新启动同一个作业实例时,它应该抛出异常。然而从你的问题来看,你的工作似乎可以重新开始。我怀疑你在启动工作时是否传递了相同的工作参数。阿德里安,有什么具体的方法传递工作参数吗?在MyTasklet1类中,我正在检查标记文件。在第一次运行中,文件不存在,因此该步骤失败。然后我放置文件并再次运行作业。在这个测试中,我再次运行同一个作业,除了标记文件外,没有做任何更改。无论何时启动作业,都应该告诉joblauncher作业名称和参数。检查spring批处理文档,这些概念应该出现在前几章中,这在我看来并不正确:您的
myCustomJob
声明为
restartable=false
,这意味着在重新启动同一个作业实例时,它应该抛出异常。然而从你的问题来看,你的工作似乎可以重新开始。我怀疑你在启动工作时是否传递了相同的工作参数。阿德里安,有什么具体的方法传递工作参数吗?在MyTasklet1类中,我正在检查标记文件。在第一次运行中,文件不存在,因此该步骤失败。然后我放置文件并再次运行作业。在这个测试中,我再次运行同一个作业,除了标记文件外,没有做任何更改。无论何时启动作业,都应该告诉joblauncher作业名称和参数。检查spring批处理文档,这些概念应该在前几章中介绍
public class MyTasklet1 implements Tasklet {

@Override
public RepeatStatus execute(StepContribution contribution,
        ChunkContext chunkContext) throws Exception {

    String s = "This is an output";

    chunkContext.getStepContext().getStepExecution().getJobExecution()
            .getExecutionContext().put("outputString", s);

    System.out.println("Inside MyTasklet1");

    File f = new File(
            "C:/MyProject/SpringBatchExampleNew/src/main/resources/marker");

    if (f.exists()) {
        System.out.println("File found");
        return RepeatStatus.FINISHED;
    } else {
        System.out.println("File not found");
        throw new Exception("File not found");
    }

}}
public class MyTasklet2 implements Tasklet {

private String output;

public String getOutput() {
    return output;
}

public void setOutput(String output) {
    this.output = output;
}

@Override
public RepeatStatus execute(StepContribution contribution,
        ChunkContext chunkContext) throws Exception {

    setOutput((String) chunkContext.getStepContext().getStepExecution()
            .getJobExecution().getExecutionContext().get("outputString"));

    Thread.sleep(500);
    System.out.println("Inside MyTasklet2");
    System.out.println("Output string is: " + output);

    return RepeatStatus.FINISHED;
}}
public class MyTasklet3 implements Tasklet {

private String output;

public String getOutput() {
    return output;
}

public void setOutput(String output) {
    this.output = output;
}

@Override
public RepeatStatus execute(StepContribution contribution,
        ChunkContext chunkContext) throws Exception {

    setOutput((String) chunkContext.getStepContext().getStepExecution()
            .getJobExecution().getExecutionContext().get("outputString"));

    System.out.println("Inside MyTasklet3");
    System.out.println("Output string is: " + output);

    return RepeatStatus.FINISHED;

}}