Results 1 to 7 of 7

Thread: How to specify job parameters for endOfDayJob?

  1. #1
    Join Date
    Dec 2010
    Posts
    175

    Question How to specify job parameters for endOfDayJob?

    Hello,

    I've performed basic endOfDayJob Setup and I'm able to run this using my batch-test and it works as expected.

    Now, I've added Quartz scheduler to run it every end of day. however, it throws the exceptions like
    Code:
    org.springframework.batch.core.repository.JobExecutionAlreadyRunningException: A job execution for this job is already running: JobInstance: id=172, version=0, JobParameters=[{}], Job=[loadFile]
    	at org.springframework.batch.core.repository.support.SimpleJobRepository.createJobExecution(SimpleJobRepository.java:116)
    	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:79)
    	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    	at java.lang.reflect.Method.invoke(Method.java:618)
    each job execution should be specific to the day it is being executed. I know it is controlled by JobParameters but where and how do I specify it?

  2. #2
    Join Date
    Dec 2005
    Location
    Lyon, France
    Posts
    311

    Default

    you specify job parameters when launching the job, with the JobLauncher.run(Job, JobParameters) method.

  3. #3
    Join Date
    Dec 2010
    Posts
    175

    Default

    Thanks for the reply.

    But, where in spring configuration do you specify and how?

    is it going to be in <job /> or somewhere else? any examples please!

  4. #4
    Join Date
    Dec 2005
    Location
    Lyon, France
    Posts
    311

    Default

    nowhere in the configuration: this a Java API. It depends on the way you launch your jobs. How do you launch the job?

  5. #5
    Join Date
    Dec 2010
    Posts
    175

    Default

    The reported exception is expected when a job is run with same parameters. In my case it will be successful only once because there are no job parameters specified [see my original post].

    I'm launching the job using quartz as shown in spring batch reference

    Code:
    <bean id="jobDetail" class="org.springframework.scheduling.quartz.JobDetailBean">
        <property name="jobClass" value="org.springframework.batch.sample.quartz.JobLauncherDetails" />
        <property name="group" value="quartz-batch" />
        <property name="jobDataAsMap">
            <map>
                <entry key="jobName" value="footballJob"/>
                <entry key="jobLocator" value-ref="jobRegistry"/>
                <entry key="jobLauncher" value-ref="jobLauncher"/>
            </map>
        </property>
    </bean>
    
    <bean class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
      <property name="triggers">
        <bean id="cronTrigger" class="org.springframework.scheduling.quartz.CronTriggerBean">
          <property name="jobDetail" ref="jobDetail" />
          <property name="cronExpression" value="0/10 * * * * ?" />
        </bean>
      </property>
    </bean>

  6. #6
    Join Date
    Dec 2005
    Location
    Lyon, France
    Posts
    311

    Default

    the sample doesn't provide any job parameter, that's why the first launch works and you get an JobExecutionAlreadyRunningException then. You should take a look at the JobLauncherDetails code and at the Spring/Quartz integration to see how to specify job parameters (with Quartz's job map). You can also choose Spring Scheduling (which is simpler than Quartz, but requires Spring 3.0).

  7. #7
    Join Date
    Dec 2010
    Posts
    175

    Default

    Thank you. As of now, I'm adding a job parameter from JobLauncherDetails.

Posting Permissions

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