I am new to spring batch processing . Just wanted few suggestion so that i could connect while reading about spring batch.
My scenario is as follows: I wrote 4 java classes which would read and modify data in oracle. For example : Class1 and Class2 will modify table 1, Class3 and Class4 will modify table2
How can we parallelize execution of there classes with spring batch processiing?
Without knowing what each class does, there's a limit on how good of advice I can provide. That being said, if all you want to do is to execute each class in parallel using Spring Batch, Spring Batch provides a couple of tools to help with this:
MethodInvokingTaskletAdapter
- This Tasklet
implementation provided by Spring Batch allows you to execute a method on a specified bean in the scope of a transaction. This allows you to wrap existing classes with a Tasklet
so they can be easily consumed by Spring Batch. With the above concepts in place, you could configure your batch job to look something like the following:
<job id="job1">
<split id="split1">
<flow>
<step id="split1Step1" next="split1Step2">
<tasklet ref="class1Tasklet"/>
</step>
<step id="split1Step2">
<tasklet ref="class2Tasklet"/>
</step>
</flow>
<flow>
<step id="split2Step1" next="split2Step2">
<tasklet ref="class3Tasklet"/>
</step>
<step id="split2Step2">
<tasklet ref="class4Tasklet"/>
</step>
</flow>
</split>
</job>
<bean id="class1Tasklet" class="org.springframework.batch.core.step.tasklet.MethodInvokingTaskletAdapter">
<property name="targetObject">
<bean class="Class1"/>
</property>
<property name="targetMethod" value="someMethod"/>
</bean>
<bean id="class2Tasklet" class="org.springframework.batch.core.step.tasklet.MethodInvokingTaskletAdapter">
<property name="targetObject">
<bean class="Class2"/>
</property>
<property name="targetMethod" value="someMethod"/>
</bean>
<bean id="class3Tasklet" class="org.springframework.batch.core.step.tasklet.MethodInvokingTaskletAdapter">
<property name="targetObject">
<bean class="Class3"/>
</property>
<property name="targetMethod" value="someMethod"/>
</bean>
<bean id="class4Tasklet" class="org.springframework.batch.core.step.tasklet.MethodInvokingTaskletAdapter">
<property name="targetObject">
<bean class="Class4"/>
</property>
<property name="targetMethod" value="someMethod"/>
</bean>
You can read more about the MethodInvokingTaskletAdapter
in the documentation here: http://docs.spring.io/spring-batch/apidocs/org/springframework/batch/core/step/tasklet/MethodInvokingTaskletAdapter.html
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.