Results 1 to 2 of 2

Thread: Setting ExecutionContext Before Launch

  1. #1
    Join Date
    Jul 2008
    Posts
    21

    Default 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. #2
    Join Date
    Feb 2008
    Posts
    488

    Default

    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.

Posting Permissions

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