Announcement Announcement Module
Collapse
No announcement yet.
Batch execution status Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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
    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.

    Comment


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

      Comment


      • #4
        Have a look at this: 4.1.2. Intercepting Job execution

        Comment


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

          Comment


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

            Comment


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

              Comment


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

                Comment

                Working...
                X