Announcement Announcement Module
Collapse
No announcement yet.
How to specify job parameters for endOfDayJob? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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
    you specify job parameters when launching the job, with the JobLauncher.run(Job, JobParameters) method.

    Comment


    • #3
      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!

      Comment


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

        Comment


        • #5
          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>

          Comment


          • #6
            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).

            Comment


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

              Comment

              Working...
              X