Spring batch SpringBatch中SimpleAsyncTaskExecutor与SyncTaskExecutor的比较

Spring batch SpringBatch中SimpleAsyncTaskExecutor与SyncTaskExecutor的比较,spring-batch,Spring Batch,我有一个SpringBatch应用程序,我们正在尝试并行处理。在批处理中,它从一个表中读取数据,并使用响应更新另一个表。如果输入表中有100条记录,那么输出表也应该有100条记录 现在,输入表中有13600条记录。当我尝试使用SyncTaskExecutor时,只有一个线程在运行,输出表得到13600条记录。当我尝试使用SimpleAsyncTaskExecutor时,输出表中只有900条记录 职位声明如下: <?xml version="1.0" encoding="UTF-8"?>

我有一个SpringBatch应用程序,我们正在尝试并行处理。在批处理中,它从一个表中读取数据,并使用响应更新另一个表。如果输入表中有100条记录,那么输出表也应该有100条记录

现在,输入表中有13600条记录。当我尝试使用
SyncTaskExecutor
时,只有一个线程在运行,输出表得到13600条记录。当我尝试使用
SimpleAsyncTaskExecutor
时,输出表中只有900条记录

职位声明如下:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:task="http://www.springframework.org/schema/task"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
    http://www.springframework.org/schema/batch http://www.springframework.org/schema/batch/spring-batch-2.1.xsd
    http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-3.1.xsd">

<import resource="applicationContext.xml" />


<bean id="itemReader"
    class="org.springframework.batch.item.database.JdbcCursorItemReader">
    <property name="dataSource" ref="dataSource" />
    <property name="sql" value="select REP_QMUT_KEY, DLN_DLNRNR, DLN_AFVDAT, F_IND_MEMO_DVB, MUT_MUTDAT_UM, MUT_VERWDAT_UM, MUT_SRT_MUT_UM from REP_QMUT" />
    <property name="rowMapper">
        <bean class="com.aegon.quinto.service.mapper.MutationInputRowMapper" />
    </property>
</bean>
<bean id="simpleStep"
    class="org.springframework.batch.core.step.item.SimpleStepFactoryBean">
    <property name="transactionManager" ref="transactionManager" />
    <property name="jobRepository" ref="jobRepository" />
    <property name="itemReader" ref="itemReader" />
    <property name="itemWriter" ref="itemWriter" />
    <property name="commitInterval" value="10" />
    <property name="startLimit" value="1" />
</bean>

 <bean id="itemWriter" class="org.springframework.batch.item.database.JdbcBatchItemWriter">
    <property name="dataSource" ref="dataSource" />
    <property name="itemSqlParameterSourceProvider">
        <bean class="org.springframework.batch.item.database.BeanPropertyItemSqlParameterSourceProvider" />
    </property>
    <property name="sql" value="INSERT INTO MUT_TRIAL(DLNRNR, AFVDAT,  MEMO_MUTATION, MEMO_PARTICIPANT, MUTATION_DATE, PROCESSING_DATE, RUN_NR, SRT_MUT, REP_QMUT_CORTICON_KEY) VALUES (:dlnrnr,:afvDat,:memo,:participantMemo,:mutationDate,:processDate,:runNr,:mutationType,:mutationKey)" />
    </bean>

<bean id="simpleChunkListner" class="com.aegon.quinto.service.listener.SimpleChunkListener" />

<bean id="taskExecutor" class="org.springframework.core.task.SyncTaskExecutor" />
<bean id="itemProcessor" class="com.aegon.quinto.service.processor.SimpleItemProcessor" />

<!-- job id="simpleJob" xmlns="http://www.springframework.org/schema/batch">
    <step id="simpleStep">
        <tasklet>
            <chunk reader="itemReader"  writer="itemWriter"
                commit-interval="50">
            </chunk>
        </tasklet>
    </step>

</job-->

<job id="simpleJob" xmlns="http://www.springframework.org/schema/batch">
    <step id="simpleStep">
        <tasklet task-executor="taskExecutor" throttle-limit="25">
            <chunk reader="itemReader"  processor="itemProcessor" writer="itemWriter"
                commit-interval="50">
            </chunk>
        </tasklet>
    </step>

</job>


<!--  For running the BatchLauncher -->
<bean id="batchLauncher" class="com.aegon.quinto.service.BatchLauncher">
    <property name="jobLauncher" ref="jobLauncher" />
    <property name="jobRepository" ref="jobRepository" />
    <property name="job" ref="simpleJob" />
</bean>
</beans>
导入java.sql.SQLException

导入org.springframework.jdbc.core.RowMapper

导入com.aegon.quinto.model.mutationput

公共类MutationInputRowMapper实现了RowMapper{

public Object mapRow(ResultSet rs, int rowNum) throws SQLException {
    // TODO Auto-generated method stub
    MutationInput mutationInput = new MutationInput();
    mutationInput.setMutationKey(rs.getInt("REP_QMUT_KEY"));
    mutationInput.setDlnrnr(rs.getString("DLN_DLNRNR"));
    mutationInput.setMemo(rs.getString("F_IND_MEMO_MVM"));
    mutationInput.setParticipantMemo(rs.getString("F_IND_MEMO_DVB"));
    mutationInput.setProcessDate(rs.getInt("MUT_VERWDAT_UM"));
    mutationInput.setRunNr(new Integer("2"));
    mutationInput.setMutationType(rs.getString("MUT_SRT_MUT_UM"));

    return mutationInput;
}
}

我的总体要求如下: 我将从输入表中读取数据,使用外部服务验证数据,并更新输出表中的验证响应。在输入表中,数据将采用平面结构。i、 对于一个学生来说,可能会有多次考试的结果。在前往外部服务之前,我需要检索该参与者的所有考试结果。 由于网络延迟,与外部服务的通信将成为瓶颈。因此,需要多线程。 如果有任何示例实现/指南,请给我指路。
注:我是SpringBatch的新手。

看起来您的一个或多个组件不是线程安全的

看起来您的一个或多个组件不是线程安全的

也添加taskExecutor的配置。taskExecutor的配置位于code@Rajkumar当你说使用时只写了900条记录SimpleAsyncTaskExecutor,作业状态是否已完成?也添加taskExecutor的配置。taskExecutor的配置位于code@Rajkumar当您说使用SimpleAsyncTaskExecutor时只写入了900条记录,作业状态是否已完成?我正在使用
JdbcCursorItemReader
JdbcBatchItemWriter
进行读写操作。我应该使用其他阅读器吗?阅读器、处理器和写入器之间有更多的组件、itemProcessor和使用的数据对象,请将它们全部发布:-)谢谢Michael。在上面添加了整个xml。为什么有2个simpleStep配置?也可以添加源吗?尤其是来自mapper和processorI的您自己的代码,我使用
JdbcCursorItemReader
JdbcBatchItemWriter
进行读写。我应该使用其他阅读器吗?阅读器、处理器和写入器之间有更多的组件、itemProcessor和使用的数据对象,请将它们全部发布:-)谢谢Michael。在上面添加了整个xml。为什么有2个simpleStep配置?也可以添加源吗?特别是来自映射器和处理器的您自己的代码
public Object mapRow(ResultSet rs, int rowNum) throws SQLException {
    // TODO Auto-generated method stub
    MutationInput mutationInput = new MutationInput();
    mutationInput.setMutationKey(rs.getInt("REP_QMUT_KEY"));
    mutationInput.setDlnrnr(rs.getString("DLN_DLNRNR"));
    mutationInput.setMemo(rs.getString("F_IND_MEMO_MVM"));
    mutationInput.setParticipantMemo(rs.getString("F_IND_MEMO_DVB"));
    mutationInput.setProcessDate(rs.getInt("MUT_VERWDAT_UM"));
    mutationInput.setRunNr(new Integer("2"));
    mutationInput.setMutationType(rs.getString("MUT_SRT_MUT_UM"));

    return mutationInput;
}