spring batch vs quartz jobs?

怎甘沉沦 提交于 2019-12-20 12:41:12

问题


I am new to batch processing. I am trying to start with simple scheduler and job. But i am confused b/w spring batch vs quartz jobs. My understanding is

Quartz :- quartz provides both frameworks i.e scheduler framework and job framework(in case I do not want to use spring batch jobs). Right ?

Spring Batch :- It only provides the job framework . I have always send using Quatz schecduler to schedule spring batch jobs. Does spring provides its own scheduler also ?


回答1:


Quartz is a scheduling framework. Like "execute something every hour or every last friday of the month"

Spring Batch is a framework that defines that "something" that will be executed. You can define a job, that consists of steps. Usually a step is something that consists of item reader, optional item processor and item writer, but you can define a custom stem. You can also tell Spring batch to commit on every 10 items and a lot of other stuff.

You can use Quartz to start Spring Batch jobs.

So basically Spring Batch defines what should be done, Quartz defines when it should be done.




回答2:


There is answer for this question in official FAQ

How does Spring Batch differ from Quartz?

Is there a place for them both in a solution? Spring Batch and Quartz have different goals. Spring Batch provides functionality for processing large volumes of data and Quartz provides functionality for scheduling tasks. So Quartz could complement Spring Batch, but are not excluding technologies. A common combination would be to use Quartz as a trigger for a Spring Batch job using a Cron expression and the Spring Core convenience SchedulerFactoryBean.




回答3:


Does spring provides its own scheduler also?

Yes, using Spring TaskScheduler as follows:

 <task:scheduled-tasks>
    <task:scheduled ref="runScheduler" method="run" fixed-delay="5000" />
  </task:scheduled-tasks>

  <task:scheduled-tasks>
    <task:scheduled ref="runScheduler" method="run" cron="*/5 * * * * *" />
  </task:scheduled-tasks>

full example

With Quartz Scheduler as follows:

  <!-- run every 10 seconds -->
  <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="*/10 * * * * ?" />
      </bean>
    </property>
  </bean>

full example



来源:https://stackoverflow.com/questions/33188368/spring-batch-vs-quartz-jobs

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!