Announcement Announcement Module
Collapse
No announcement yet.
Putting values in JobExecutionContext Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Putting values in JobExecutionContext

    Hi,

    How do I put some values in the JobExecutionContext from a Tasklet?

    I have tried the following, but getting back an error saying that the map is unmodifiable?

    Code:
    public RepeatStatus execute(StepContribution arg0, ChunkContext arg1) {
    
    Sring value = "test";
    		arg1.getStepContext().getJobExecutionContext().put("KEY", value);

  • #2
    Alos tried this in the tasklet:

    Code:
    public ExitStatus afterStep(StepExecution stepExecution) {
    		
    		Date now = new Date();
    		
    		stepExecution.getJobExecution().getExecutionContext().putString(PROV_CODE_KEY, province_code);
    		stepExecution.getJobExecution().getExecutionContext().putString(ASS_BODY_CODE_KEY, ass_body_code);
    		stepExecution.getJobExecution().getExecutionContext().putString(ASS_BODY_NAME_KEY, ass_body_name);
    		stepExecution.getJobExecution().getExecutionContext().putLong(SEQ_RUN_NUMBER_KEY, seq_run_number);
    		stepExecution.getJobExecution().getExecutionContext().putString(DAY_KEY, dayFormat.format(now));
    		stepExecution.getJobExecution().getExecutionContext().putString(MONTH_KEY, monthFormat.format(now));
    		stepExecution.getJobExecution().getExecutionContext().putString(YEAR_KEY, yearFormat.format(now));
    		
    		
    		return ExitStatus.COMPLETED;
    	}
    Again no luck.

    In the second step I try this:

    Code:
    <beans:property name="resource"
    			value="file://c:/temp/OZEKS.E#{jobExecutionContext[PROV_CODE_KEY]}.I#{jobExecutionContext[ASS_BODY_CODE_KEY]}CS#{jobExecutionContext[SEQ_RUN_NUMBER_KEY]}.DA.#{jobExecutionContext[YEAR_KEY]}#{jobExecutionContext[MONTH_KEY]}#{jobExecutionContext[DAY_KEY]}.txt" />
    	</beans:bean>
    but they are not resolved.

    Comment


    • #3
      Your approach with the afterStep method seems right. Is your resource bean in the configuration "step-scoped"?

      Comment


      • #4
        I'm using the delegate pattern in my resource bean (or lets call it my CustomFlatFileItemWriter).

        As delegate I use the normal FlatFileItemWriter.

        My CustomFlatFileItemwriter doesn't have a Resource field, only a setResource method which calls delegate.setResource.

        In my config I configure the resource as above in my CustomFlatFileItemwriter, which is step scoped.

        My delegate is not explicitly set as step scoped in the config . Could this be the problem?

        Comment


        • #5
          Or is the step scoped bean actually the culprit? That surely doesn't sound right? Whether or not the resource bean is step scope shouldn't impact on the JobExecutionContext, or am I wrong?

          Comment


          • #6
            Guys any input will help. I urgently need this to work, I have tried several different configs, playing around with step scope etc. It's still not resolving.

            Let me break it down:

            Step 1 = Tasklet with execute method
            Retrieved data from my db needed in step 2 for the filename
            I have tried setting this as normal and step scope

            Step2 = Normal step, Reader, processor, compositewriter.
            First writer in my compositeWriter is CustomFlatFileItemWriter with delegate
            FlatfileItemWriter. Tried step scope on 1 and both.

            Any furher Ideas, or will I be forced to used some kind of threaedlocal implementation to store my values?

            Comment


            • #7
              Ok I tried something else. In my CustomFlatFileItemWriter I placed a breakpoint in the setResource method (that calls delegate.setResource) and I also implemented StepExecutionListener and the beforeStep method and registered my Writer as a listener to the step.

              Funny thing, setResource is called first (even before beforeStep ) and at this time the EL does not get resolved.

              If I continue my debug I next get into the beforeStep method, and on inspection my jobExecutionContext is populated with the correct values from my first step.

              How can I get my EL late binding to work? Or should I just set my resource in java code in the beforeStep method (I'm sure it will complain)

              Comment

              Working...
              X