Announcement Announcement Module
No announcement yet.
JobRepository.createJobExecution(String, JobParameters) Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • JobRepository.createJobExecution(String, JobParameters)

    I'm fooling with the following:

    In a Junit test case I have this:
    JobExecution jobEx = repository.createJobExecution(String name, JobParameters params);

    Running the above line creates a row in (among others) the Batch_Job_Execution table with a Job_Execution_ID, a Job_Instance_ID and with the STATUS=starting and EXIT_CODE=unknown.

    That is all, the test case ends. So far so good?

    In another method in another Junit test case, I try and restart thatjob using the JobOperator. I retrieve the executionID from the database:
    operator.restart(Long executionID)

    I get the Exception that the job is already running.

    What am I missing here?

    What is the purpose of repository.createJobExecution(--) method? Why would I be interested in it?

    I can envision the use case where I might create some number of JobExecutions and go back and run them later, but the framework is not permitting me to do this.

    Thanks in advance for you comments.

  • #2
    Look at JobExecution.isRunning(). Until the execution is updated in the job repository with a status and an endTime, the JobLauncher which you are using indirectly through the JobOperator, assumes that it is still running.

    JobRepository.createJobExecution() is there for the benefit of clients who want to launch a job execution (specifically a JobLauncher). You probably aren't interested in it as a normal user - only if you want to write your own JobLauncher.