Results 1 to 8 of 8

Thread: Batch execution status

  1. #1
    Join Date
    Apr 2009
    Posts
    17

    Default Batch execution status

    Hi,
    How do I determine if the Batch has completed succesfully. This is where I m coming from. upon successful completion of batch, my application has to send an email to list of recipients from the properties file. where do I do this?

    Thanks

  2. #2
    Join Date
    Feb 2009
    Location
    Montreal, Qc, Canada
    Posts
    23

    Default

    Hello,

    You can implement and register a JobExecutionListener. There's an "afterJob" method which has a JobExecution parameter. The JobExecution has an "ExitStatus" property.

    Gino.

  3. #3
    Join Date
    Apr 2009
    Posts
    17

    Default

    Thank you. But how do I implement and register a listener. Sorry I m still learing spring batch.:o

  4. #4
    Join Date
    Feb 2009
    Location
    Montreal, Qc, Canada
    Posts
    23

    Smile

    Have a look at this: 4.1.2. Intercepting Job execution

  5. #5
    Join Date
    Apr 2009
    Posts
    17

    Default

    Thanks.
    But I m using Spring 1.1.4 version. As per documentation I used the following in my xml
    Code:
    <property name="jobListeners">
       <bean class="org.springframework.batch.core.listener.JobListenerSupport" />
      </property>
    But I m getting the following error while executing
    Code:
     nested exception is java.lang.ClassNotFoundException: org.springframework.batch.core.listener.JobListenerSupport
    A m I missing anything here?

  6. #6
    Join Date
    Feb 2008
    Posts
    488

    Default

    I would send the email from the last step of the job:
    Code:
    <job id="job1">
        <step id="step1" ... next="sendEmail" />
        <step id="sendEmail">
            <tasklet ref="emailSendingTasklet"/>
        </step
    </job>
    Using the "next" attribute of the <step/> means "go to this next step if successful". If the step fails, then the next step will not execute.

    This approach is better than the listener approach because it can handle errors. If an exception is thrown from a listener, is doesn't affect the status of the job. It is also not possible to restart the job in order to recover.

    By having a separate "sendEmail" step, you ensure that if the email fails to send, the step and job will fail. You will also be able to restart the job, and it will try again to send the email, without having to start the job from the beginning.

  7. #7
    Join Date
    Feb 2008
    Posts
    488

    Default

    The same idea applies in Spring Batch 1.1.4; you just don't use the namespace. Just put the email-sending step as the last step in the job and you'll get the same result as I described above.

  8. #8
    Join Date
    Jun 2005
    Posts
    4,231

    Default

    Quote Originally Posted by sundarvarad View Post
    A m I missing anything here?
    The class name is not spelled correctly. Did you mean "JobExecutionListenerSuport"? (Since this is an empty method implementation of the interface it doesn't really make sense to use a raw instance - you need to extend it, as per the documentation examples.)

Posting Permissions

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