This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes Spring and the fly likes Spring Batch - custom tasklet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Frameworks » Spring
Bookmark "Spring Batch - custom tasklet" Watch "Spring Batch - custom tasklet" New topic
Author

Spring Batch - custom tasklet

Kunjal Shah
Greenhorn

Joined: Aug 28, 2005
Posts: 13
I have a Spring Batch job with sequence of Steps (with ItemReader, an optional ItemProcessor, ItemWriter). There are multiple Steps but the most use FlatFileItemReader/Writer to read in a CSV file and do some operations based on the item (single row read).

Now I need to have to read in the CSV file (as a whole) and create a Map object that I need in batch Steps. I was thinking of having a custom Tasklet to do this (read in the CSV file and create the map to put in Execution Context which can be later read in the Steps). I was wondering if this is a good solution for this ? If anybody has done something similar would appreciate any inputs...
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17250
    
    6

Yes you can implement a custom ItemWriter that just writes to that map object, then put that map object into the JobRepository so that it is available to other steps.

Mark


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
Saifuddin Merchant
Ranch Hand

Joined: Feb 08, 2009
Posts: 605

Mark Spritzler wrote:Yes you can implement a custom ItemWriter that just writes to that map object, then put that map object into the JobRepository so that it is available to other steps.

Mark


Remember that the job repository (and I'm assuming you mean the Execution Context - either Step or Job) gets committed to the database at commit interval (depending on the type - Step or Job) so you've effectively writing the entire Map to the database on each commit point.
That may or may not be a problem - depending on how big your file is.

A solution would be to stage the records in a "table" and then update them as needed as you move along the steps ...


Cheers - Sam.
Twisters - The new age Java Quiz || My Blog
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Spring Batch - custom tasklet