java - Spring Batch, variable through the steps of a job -


i'm trying create job in spring batch can't find something.. program looks :

  • a tasklet wich create list of ids
  • a reader use list string in database , concatenated them
  • a writer take string , write in file
  • a tasket use list of ids , update database.

first, best choice structure of batch ?

the main problem don't know how list of ids in reader , in last tasklet. i'm using spring , i've tried :

    <bean id="idlist" class="java.util.arraylist" scope="job" />      <bean id="myfirsttasklet" class="myfirsttasklet"         <property name="idlist" ref="idlist" />     </bean>      <bean id="myreader" class="myreader"         <property name="idlist" ref="idlist" />     </bean>      <bean id="mysecondtasklet" class="mysecondtasklet"         <property name="idlist" ref="idlist" />     </bean> 

can list updated tasklet before creation of reader , second tasklet ?

you can put value in executioncontext of tasklet , later retrieve in other tasklet. see code below:

inside 1st tasklet-

public repeatstatus execute(stepcontribution stepcontribution,         chunkcontext chunkcontext) throws exception {  //putting value in execution context chunkcontext.getstepcontext().getstepexecution().getjobexecution()             .getexecutioncontext()             .put(constants.data_list, idlist); 

}

inside 2nd tasklet:

public repeatstatus execute(stepcontribution contribution,         chunkcontext chunkcontext) throws exception {  //retrieving value execution context (arraylist) chunkcontext.getstepcontext()             .getstepexecution().getjobexecution().getexecutioncontext()             .get(constants.data_list);   } 

also ensure mark scope of tasklet step:

<bean id="mysecondtasklet" class="mysecondtasklet" scope="step" > 

Comments

Popular posts from this blog

qt - Using float or double for own QML classes -

Create Outlook appointment via C# .Net -

ios - Swift Array Resetting Itself -