spring整合Quartz跟使用原生的api的区别主要是在于调度对象实现的方式。

原生的Quartz任务调度实现方式可以参考原生Quartz动态任务调度实现

下面基于上面的原生Quartz动态任务调度实现讲下如何整合spring来实现。

整合spring,主要就是声明SchedulerFactoryBean。

这个是spring实现的任务调度对象。

在spring.xml里头声明:

    <bean id="scheduler" class="org.springframework.scheduling.quartz.SchedulerFactoryBean" lazy-init="true">
        <!--<property name="dataSource" ref="dataSource"/>-->
        <property name="schedulerName" value="mainScheduler"/>
        <!--<property name="jobSchedulingDataLocations" value="classpath:quartz/quartz-data.xml"/>-->
        <!--<property name="quartzProperties">-->
            <!--<props>-->
                <!--<prop key="org.quartz.scheduler.instanceId">AUTO</prop>-->
                <!--<prop key="org.quartz.scheduler.skipUpdateCheck">true</prop>-->
                <!--<prop key="org.quartz.threadPool.class">org.quartz.simpl.SimpleThreadPool</prop>-->
                <!--<prop key="org.quartz.threadPool.threadCount">30</prop>-->
                <!--<prop key="org.quartz.threadPool.threadPriority">5</prop>-->
                <!--<prop key="org.quartz.jobStore.class">org.quartz.impl.jdbcjobstore.JobStoreTX</prop>-->
                <!--<prop key="org.quartz.jobStore.driverDelegateClass">org.quartz.impl.jdbcjobstore.StdJDBCDelegate</prop>-->
                <!--<prop key="org.quartz.jobStore.useProperties">false</prop>-->
                <!--<prop key="org.quartz.jobStore.tablePrefix">QRTZ_</prop>-->
                <!--<prop key="org.quartz.jobStore.isClustered">true</prop>-->
                <!--<prop key="org.quartz.jobStore.misfireThreshold">60000</prop>-->
            <!--</props>-->
        <!--</property>-->
    </bean>

在调用时候:

    @Resource(name = "scheduler")
    private Scheduler scheduler;

上面的scheduler就是后面要用的调度对象,只有这个区别。

Logo

北京人形旗下天工造物具身智能开源社区,聚焦具身天工与慧思开物两大平台

更多推荐