Announcement Announcement Module
Collapse
No announcement yet.
Setting ExecutionContext Before Launch Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Setting ExecutionContext Before Launch

    Hello,

    Quick question... What is the best way to set a job's execution context before using a launcher to launch a job?

    Before I go and extend JobLauncher, I'd like to know if it is possible to set the execution context for a job before launching it through a JobLauncher. I am using SimpleJobLauncher right now to run jobs, but I need to conditionally park a value in execution context before I run it.

    Code:
    // create execution
    JobExecution jobExecution = jobRepository.createJobExecution(job.getName(), jobParameters);			
    
    // set context values...
    
    // update execution
    this.jobRepository.update(jobExecution);
    
    // run job
    fuzzy - run job given an execution?!

    Thanks,

    Alejandro

  • #2
    One easy way is to put a @BeforeJob method in a class and have that method dump values to the ExecutionContext:
    Code:
    @BeforeJob
    public void dumpValues(JobExecution je){
        je.getExecutionContext().put("key", value);
    }
    Then just wire this listener into your job.

    The values inserted can come from anywhere. They can be hard-coded or you could have them be configurable from the XML context.

    Comment

    Working...
    X