spring定时器
程序员文章站
2022-06-12 21:11:19
...
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd"> <bean id="rebateJob" class="org.springframework.scheduling.quartz.JobDetailBean"> <property name="jobClass"> <value>com.rebate.scheduled.job.RebateQuartz</value> </property> </bean> <!-- 复杂触发器 --> <bean id="rebateCronTrigger" class="org.springframework.scheduling.quartz.CronTriggerBean"> <property name="jobDetail"> <ref bean="rebateJob" /> </property> <property name="cronExpression"> <!-- 配置时间 6至9时每5分钟执行一次--> <value>0 0/5 6-9 * * ?</value> <!--测试用的--> <!--<value>0/3 * * * * ?</value>--> </property> </bean> <bean id="scheduler" class="org.springframework.scheduling.quartz.SchedulerFactoryBean"> <property name="triggers"> <ref bean="rebateCronTrigger" /> </property> <property name="autoStartup"> <value>false</value> </property> </bean> </beans>
定时运行的东西
import org.quartz.JobExecutionContext; import org.quartz.JobExecutionException; import org.springframework.scheduling.quartz.QuartzJobBean; public class RebateQuartz extends QuartzJobBean { protected void executeInternal(JobExecutionContext context) throws JobExecutionException {} }
启动
import org.quartz.impl.StdScheduler; import org.springframework.context.ApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext; public class AutoRebate { public static void main(String[] args) throws Exception { ApplicationContext context = new ClassPathXmlApplicationContext( "classpath*:/spring/*.xml"); StdScheduler scheduler = (StdScheduler) context.getBean("scheduler"); scheduler.start(); } }
上一篇: 雷人的脑筋急转弯
下一篇: 更年期怎么办? 更年期如何调理月经不调
推荐阅读