spring批处理:作业状态已完成,但在使用SyncTaskExecutor时未提交任何数据

时间:2017-08-22 07:16:15

标签: java spring spring-batch

这是我的工作结构。

<bean id="ControlJob" class="com.example.batch.ControlJob">
<property name="jobRepository" ref="jobRepository" />
<property name="name" value="Outter job" />
<property name="moduleId" value="d" />
<property name="jobList">
  <list>
    <ref bean="a" />
    <ref bean="b" />
    <ref bean="c" />
    <ref bean="d" />
    <ref bean="e" />
    <ref bean="f" />
    <ref bean="g" />
    <ref bean="h" />
  </list>
</property>
<property name="jobLauncher" ref="jobLauncher" />
</bean>

<bean id="jobLauncher" class="org.springframework.batch.core.launch.support.SimpleJobLauncher">
    <property name="taskExecutor" ref="syncTaskExecutor" />
    <property name="jobRepository" ref="jobRepository" />
</bean>

<bean id="syncTaskExecutor" class="org.springframework.core.task.SyncTaskExecutor" />

这是我的入口:

public class SimpleJobLauncher {

public static void main(String[] args) {
    String[] path = {"classpath:com/context.xml"};
    AbstractApplicationContext context = new FileSystemXmlApplicationContext(path);
    context.registerShutdownHook();

    IBatchJobControllerBO batch = (IBatchJobControllerBO) context.getBean("batchJobControllerBO");
    //IBatchJobControllerBO batch = (IBatchJobControllerBO) context.getBean("synchronizedBatchJobControllerBO");
    try {
        BatchJobExecution execution = batch.startBatchJob("Outter job");
        //BatchJobExecution execution = batch.startBatchJob("Outter job");
        String message = execution.getExitMessage();
        System.out.println("job completed: " + message);
    } catch (Exception e) {
        e.printStackTrace();
    }

}
}

两个不同的bo来运行Outter工作:

<bean id="batchJobControllerBO"
    class="com.bo.impl.BatchJobControllerBOImpl">
    <property name="jobLauncher" ref="jobLauncher" />
    <property name="jobRegistry" ref="jobConfigurationRegistry" />
    <property name="batchJobDAO" ref="batchJobDAO" />
    <property name="batchJobExecutionDAO" ref="batchJobExecutionDAO" />
</bean>

<bean id="jobLauncher"
    class="org.springframework.batch.core.launch.support.SimpleJobLauncher">
    <property name="jobRepository" ref="jobRepository" />
    <property name="taskExecutor">
        <bean class="org.springframework.core.task.SimpleAsyncTaskExecutor" />
    </property>
</bean> 

<bean id="synchronizedBatchJobControllerBO" parent="batchJobControllerBO" 
    class="com.bo.impl.BatchJobControllerBOImpl">
    <property name="jobLauncher" ref="synchronizeJobLauncher" />
</bean>

<bean id="synchronizeJobLauncher" parent="jobLauncher"
    class="org.springframework.batch.core.launch.support.SimpleJobLauncher">
    <property name="taskExecutor">
        <bean class="org.springframework.core.task.SyncTaskExecutor" />
    </property>
</bean> 

如果我使用jobLauncher,那么每个作业a~h都能正常工作,而对于Outter Job:&#34; SimpleAsyncTaskExecutor&#34;打电话给外出工作,它会正常工作。

但是当我使用jobLauncher:&#34; SyncTaskExecutor&#34;要调用Outter Job,一些工作(错误不稳定)没有向DB提交任何数据(表是空的)。

作业状态已完成且没有任何错误。

有人能告诉我这种情况有什么不对吗?

0 个答案:

没有答案