Results 1 to 10 of 11

Thread: How To: Read Once and Write 3 times in parallel

Hybrid View

  1. #1
    Join Date
    Aug 2006
    Location
    Arequipa-Peru / South America
    Posts
    2,796

    Question How To: Read Once and Write 3 times in parallel

    Hello guys

    I have the follow situation working with these tables for an exposition.

    Code:
    Customer 
    id      firstname lastname
    000001  manuel01  jordan01
    ....
    000500  manuel500  jordan500
    and

    Code:
    Currency
    id    description
    1     sol  
    2     dolar  
    3     euro
    I want generate in batch for each Customer three CustomerAccount records
    I mean

    Code:
    CustomerAccount
    id           ammount
    000001-1     500
    000001-2     500
    000001-3     500
    ....
    000500-1     500
    000500-2     500
    000500-3     500
    a total of 1500 records for CustomerAccount table

    BTW
    idCustomerAccount = idCustomer - idCurrency

    Practically three independent combinations of 500 for each group, making the total of 1500

    Therefore

    I need read the 500 Customers just once and write in parallel the three possible combinations

    000500-1 500
    000500-2 500
    000500-3 500

    I think make it in parallel but I need mandatory a writer, the processor is optional, I mean

    Code:
    <job id=""
    	<step id="alfa"
        	  read="500 customers"
          	  write <---------------- mandatory, but I dont need it
          	  next="parallel"
    	/>
    	<split id="parallel" next="...">
    		<flow>	
    			<step id="A1"
    			      reader="" <---  mandatory, I dont need it, I need work with each Customer retrieved in "alfa"   
    			      processor="" <-- I need it to create CustomerAccount related with Customer and Currency(1) Sol
    			      writer=""<--- I need it to write CustomerAccount
    			/>			
    		<flow>
    		<flow>	
    			<step id="A2"
    			      reader="" <---  mandatory, I dont need it, I need work with each Customer retrieved in "alfa"   
    			      processor="" <-- I need it to create CustomerAccount related with Customer and Currency(2) Dolar
    			      writer=""<--- I need it to write CustomerAccount
    			/>
    		<flow>	
    		<flow>	
    			<step id="A3"
    			      reader="" <---  mandatory, I dont need it, I need work with each Customer retrieved in "alfa"   
    			      processor="" <-- I need it to create CustomerAccount related with Customer and Currency(1) Euro
    			      writer=""<--- I need it to write CustomerAccount
    			/>
    		<flow>
    	
    	</split>
    	....
    </job>
    Practically A1,A2,A3 makes the 1500 rows for CustomerAccount (500 each A#), I hope you see my point.

    Code:
    000001-1 to 000500-1  Sol
    000001-2 to 000500-2  Dolar
    000001-3 to 000500-3  Euro
    I didnt try it yet, because the attributes read, write are mandatory and I dont know how pass the
    Customer from Step Alfa to each A#


    How I can handle this situation with Spring Batch?
    Is Possible?

    Thanks in advanced
    Last edited by dr_pompeii; Oct 29th, 2012 at 02:02 PM.
    - Manuel Jordan

    Kill Your Pride, Share Your Knowledge With All
    The Fear Of The LORD Is The Beginning Of Knowledge, But Fools Despise Wisdom And Discipline. Proverbs 1:7

    Blog


    Technical Reviewer of Apress

    • Pro SpringSource dm Server
    • Spring Enterprise Recipes: A Problem-Solution Approach
    • Spring Recipes: A Problem-Solution Approach, 2nd Edition
    • Pro Spring Integration
    • Pro Spring Batch
    • Pro Spring 3
    • Pro Spring MVC: With Web Flow
    • Pro Spring Security

  2. #2
    Join Date
    Sep 2008
    Location
    Chicagoland, IL
    Posts
    351

    Default

    What you are describing is called pipelining and is not supported in Spring Batch currently. Within Spring Batch, each step is responsible for obtaining it's own input which is why the reader is required.

    It sounds to me like you can do all of the above in a single multithreaded step (not knowing anything about your processing to confirm) using the reader from alpha, some form of composite of the processors in A1, A2 and A3 and the writer that you are using across A1, A2 and A3.
    Michael Minella
    Spring Batch Lead
    Author - Pro Spring Batch
    http://www.michaelminella.com
    Twitter: @MichaelMinella

  3. #3
    Join Date
    Aug 2006
    Location
    Arequipa-Peru / South America
    Posts
    2,796

    Default

    Hello Michael

    Thanks for the reply

    What you are describing is called pipelining and is not supported in Spring Batch currently.
    I see.

    Obvious question, some plans to be implemented in the future?

    Within Spring Batch, each step is responsible for obtaining it's own input which is why the reader is required.
    I understand and has sense, but my original case has sense about avoid read the data twice unnecessarily

    It sounds to me like you can do all of the above in a single multithreaded step (not knowing anything about your processing to confirm) using the reader from alpha, some form of composite of the processors in A1, A2 and A3 and the writer that you are using across A1, A2 and A3.
    I have considered about composite of the processors too.

    But my problem was how to write each different result for each composite item (because the composite of the processors approach work like a chain for each composite item) if the writer is called in the final of each step, therefore I thought in a list.

    Therefore my solution was
    How To: Write a List of Items with a ItemWriter

    Kind Regards
    - Manuel Jordan

    Kill Your Pride, Share Your Knowledge With All
    The Fear Of The LORD Is The Beginning Of Knowledge, But Fools Despise Wisdom And Discipline. Proverbs 1:7

    Blog


    Technical Reviewer of Apress

    • Pro SpringSource dm Server
    • Spring Enterprise Recipes: A Problem-Solution Approach
    • Spring Recipes: A Problem-Solution Approach, 2nd Edition
    • Pro Spring Integration
    • Pro Spring Batch
    • Pro Spring 3
    • Pro Spring MVC: With Web Flow
    • Pro Spring Security

  4. #4
    Join Date
    Sep 2008
    Location
    Chicagoland, IL
    Posts
    351

    Default

    With regards to how to write each different result of the composite item, would each processor return a different type that needs to be handled differently? I thought they all generated the same type of output. If they have different types of output, you still could do it in a single step with a ClassifierCompositeItemWriter. That would allow you to choose what writer to use for each of the items generated.
    Michael Minella
    Spring Batch Lead
    Author - Pro Spring Batch
    http://www.michaelminella.com
    Twitter: @MichaelMinella

  5. #5
    Join Date
    Aug 2006
    Location
    Arequipa-Peru / South America
    Posts
    2,796

    Default

    Thanks for the reply

    would each processor return a different type that needs to be handled differently?
    I didnt work with the composite item approach yet

    The point is that the processor must create three diferent instances of the same Object (CustomerAccount), and I am saving these 3 objects in a collection

    I thought they all generated the same type of output
    Yes, the same type CustomerAccount, but three different instances.

    I am working with the jdbcTemplate.batchupdate for this situation yet.

    Since I am able to work with ItemWriterAdapter, well I am not breaking a rule.

    I will consider of course your approach, but my time is running out
    - Manuel Jordan

    Kill Your Pride, Share Your Knowledge With All
    The Fear Of The LORD Is The Beginning Of Knowledge, But Fools Despise Wisdom And Discipline. Proverbs 1:7

    Blog


    Technical Reviewer of Apress

    • Pro SpringSource dm Server
    • Spring Enterprise Recipes: A Problem-Solution Approach
    • Spring Recipes: A Problem-Solution Approach, 2nd Edition
    • Pro Spring Integration
    • Pro Spring Batch
    • Pro Spring 3
    • Pro Spring MVC: With Web Flow
    • Pro Spring Security

  6. #6

    Default

    Quote Originally Posted by dr_pompeii View Post
    The point is that the processor must create three diferent instances of the same Object (CustomerAccount), and I am saving these 3 objects in a collection
    I haven't entirely followed what you're trying to do but if you want to do this, just return a Collection<CustomerAccount> with your three instances in your processor.

    You writer, therefore, will take a Collection<Collection<CustomerAccount>>

    S.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •