Announcement Announcement Module
Collapse
No announcement yet.
Split Steps for 2.0RC1 Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Split Steps for 2.0RC1

    Hello All,

    Since 2.0 RC1 was released, I thought I will play around it and see the new features and find out how I can make use of the new features for my future projects. While trying out parallel jobs with the split flow, I found out that it didnt actually split the steps and ran them parallely, it was just running the first step and was waiting for it to complete. Is it a bug or I am doing something wrong here. Here is the code snippet:

    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <beans:beans xmlns="http://www.springframework.org/schema/batch"
    	xmlns:beans="http://www.springframework.org/schema/beans"
    	xmlns:aop="http://www.springframework.org/schema/aop"
    	xmlns:tx="http://www.springframework.org/schema/tx"
    	xmlns:p="http://www.springframework.org/schema/p"
    	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    	xsi:schemaLocation="
    		http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
    		http://www.springframework.org/schema/batch http://www.springframework.org/schema/batch/spring-batch-2.0.xsd
    		http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd
    		http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd">
    
    	<job id="compositeItemWriterJob">
    		<split id="split1">
    			<flow>
    				<step id="step1">
    					<tasklet reader="fileItemReader"
    						writer="compositeWriter" commit-interval="1">
    						<streams>
    							<stream ref="fileItemReader" />
    							<stream ref="fileItemWriter1" />
    							<stream ref="fileItemWriter2" />
    						</streams>
    					</tasklet>
    				</step>
    			</flow>
    			<flow>
    				<step id="step2">
    					<tasklet reader="fileItemReader"
    						writer="compositeWriter1" commit-interval="1">
    						<streams>
    							<stream ref="fileItemReader1" />
    							<stream ref="fileItemWriter3" />
    							<stream ref="fileItemWriter4" />
    						</streams>
    					</tasklet>
    				</step>
    			</flow>
    		</split>
    	</job>
    
    	<!-- INFRASTRUCTURE SETUP -->
    
    	<!-- Reader setup -->
    	<beans:bean id="fileItemReader"
    		class="org.springframework.batch.item.file.FlatFileItemReader">
    		<beans:property name="resource"
    			value="file:/${user.dir}/data/inputfile.txt" />
    		<beans:property name="lineMapper">
    			<beans:bean
    				class="org.springframework.batch.item.file.mapping.DefaultLineMapper">
    				<beans:property name="lineTokenizer"
    					ref="fixedFileTokenizer" />
    				<beans:property name="fieldSetMapper"
    					ref="fieldSetMapper" />
    			</beans:bean>
    		</beans:property>
    	</beans:bean>
    
    	<beans:bean id="fixedFileTokenizer"
    		class="org.springframework.batch.item.file.transform.FixedLengthTokenizer">
    		<beans:property name="strict" value="false" />
    		<beans:property name="columns"
    			value=" 1-3, 4, 5-6, 7-8, 9, 
    					10-16, 17-18, 19-20, 21-22, 23-29,
    					30, 31, 32, 33, 34-41,
    					42-43, 44-45, 46-47, 48-49, 50,
    					51, 52, 53, 54-55, 56-61, 
    					62-66, 67, 68, 69, 70, 
    					71-72, 73-74, 75-76, 77-78, 79-80,
    					81, 113, 122, 123-150">
    		</beans:property>
    	</beans:bean>
    
    	<beans:bean id="fieldSetMapper"
    		class="com.test.fieldset.mapper.TestRecordFieldSetMapper" />
    
    	<!-- Writer setup -->
    	<beans:bean id="compositeWriter"
    		class="org.springframework.batch.item.support.CompositeItemWriter">
    		<beans:property name="delegates">
    			<beans:list>
    				<beans:bean
    					class="com.test.batch.writer.TestRecordWriter">
    					<beans:property name="marketFileWriter"
    						ref="fileItemWriter1" />
    					<beans:property name="fieldFileWriter"
    						ref="fileItemWriter2" />
    				</beans:bean>
    			</beans:list>
    		</beans:property>
    	</beans:bean>
    
    	<beans:bean id="fileItemWriter1"
    		class="org.springframework.batch.item.file.FlatFileItemWriter">
    		<beans:property name="name" value="fw1" />
    		<beans:property name="resource"
    			value="file:data/myoutput1.txt" />
    		<beans:property name="lineAggregator">
    			<beans:bean
    				class="org.springframework.batch.item.file.transform.PassThroughLineAggregator" />
    		</beans:property>
    	</beans:bean>
    
    	<beans:bean id="fileItemWriter2"
    		class="org.springframework.batch.item.file.FlatFileItemWriter">
    		<beans:property name="name" value="fw2" />
    		<beans:property name="resource"
    			value="file:data/myoutput2.txt" />
    		<beans:property name="lineAggregator">
    			<beans:bean
    				class="org.springframework.batch.item.file.transform.PassThroughLineAggregator" />
    		</beans:property>
    	</beans:bean>
    
    	<!-- SECOND STEP -->
    
    	<beans:bean id="fileItemReader1"
    		class="org.springframework.batch.item.file.FlatFileItemReader">
    		<beans:property name="resource"
    			value="file:/${user.dir}/data/input2.txt" />
    		<beans:property name="lineMapper">
    			<beans:bean
    				class="org.springframework.batch.item.file.mapping.DefaultLineMapper">
    				<beans:property name="lineTokenizer"
    					ref="fixedFileTokenizer1" />
    				<beans:property name="fieldSetMapper"
    					ref="fieldSetMapper1" />
    			</beans:bean>
    		</beans:property>
    	</beans:bean>
    
    	<beans:bean id="fixedFileTokenizer1"
    		class="org.springframework.batch.item.file.transform.FixedLengthTokenizer">
    		<beans:property name="strict" value="false" />
    		<beans:property name="columns"
    			value=" 1-3, 4, 5-6, 7-8, 9, 
    					10-16, 17-18, 19-20, 21-22, 23-29,
    					30, 31, 32, 33, 34-41,
    					42-43, 44-45, 46-47, 48-49, 50,
    					51, 52, 53, 54-55, 56-61, 
    					62-66, 67, 68, 69, 70, 
    					71-72, 73-74, 75-76, 77-78, 79-80,
    					81, 113, 122, 123-150">
    		</beans:property>
    	</beans:bean>
    
    	<beans:bean id="fieldSetMapper1"
    		class="com.test.batch.fieldset.mapper.TestFieldSetMapper" />
    
    	<!-- Writer setup -->
    	<beans:bean id="compositeWriter1"
    		class="org.springframework.batch.item.support.CompositeItemWriter">
    		<beans:property name="delegates">
    			<beans:list>
    				<beans:bean
    					class="com.test.batch.writer.TestRecordWriter">
    					<beans:property name="marketFileWriter"
    						ref="fileItemWriter3" />
    					<beans:property name="fieldFileWriter"
    						ref="fileItemWriter4" />
    				</beans:bean>
    			</beans:list>
    		</beans:property>
    	</beans:bean>
    
    	<beans:bean id="fileItemWriter3"
    		class="org.springframework.batch.item.file.FlatFileItemWriter">
    		<beans:property name="name" value="fw3" />
    		<beans:property name="resource"
    			value="file:data/output1.txt" />
    		<beans:property name="lineAggregator">
    			<beans:bean
    				class="org.springframework.batch.item.file.transform.PassThroughLineAggregator" />
    		</beans:property>
    	</beans:bean>
    
    	<beans:bean id="fileItemWriter4"
    		class="org.springframework.batch.item.file.FlatFileItemWriter">
    		<beans:property name="name" value="fw4" />
    		<beans:property name="resource"
    			value="file:data/output2.txt" />
    		<beans:property name="lineAggregator">
    			<beans:bean
    				class="org.springframework.batch.item.file.transform.PassThroughLineAggregator" />
    		</beans:property>
    	</beans:bean>
    
    </beans:beans>

  • #2
    The <split/> element has a task-executor= attribute (defaults to synchronous).

    Comment


    • #3
      By default, the split uses a SyncTaskExecutor. To have the flows process in parallel, you'll need to specify some type of AsyncTaskExecutor.

      Code:
      <job id="job">
      	<split id="split1" task-executor="taskExecutor">
      		<flow>
      			...
      		</flow>
      		<flow>
      			...
      		</flow>
      	</split>
      </job>
      	
      <beans:bean id="taskExecutor" class="org.springframework.core.task.SyncTaskExecutor" />

      Comment


      • #4
        ah.. I will give that a try!! My bad!

        Comment

        Working...
        X