SSH增加定时器
1. 新建定时器类
1 package com.webservice.crs.newtask; 2 3 import org.apache.log4j.Logger; 4 import org.quartz.JobExecutionContext; 5 import org.quartz.JobExecutionException; 6 import org.springframework.scheduling.quartz.QuartzJobBean; 7 8 public class CrrcSyncDataTimer extends QuartzJobBean { 9 10 private Logger log = Logger.getLogger(CrrcSyncDataTimer.class); 11 12 @Override 13 protected void executeInternal(JobExecutionContext arg0) throws JobExecutionException { 14 15 log.info("CRRC 人员同步定时器执行..."); 16 SDDQ_MDMService service = new SDDQ_MDMService(); 17 try { 18 service.saveDepts(); 19 service.savePosts(); 20 service.saveUsers(); 21 } catch (Exception e) { 22 log.error("CRRC 人员同步异常!", e); 23 e.printStackTrace(); 24 } 25 } 26 27 }
2. 在spring.xml中配置
1 <!-- 增量同步定时任务 --> 2 <bean id="CrrcSyncTask1" 3 class="org.springframework.scheduling.quartz.JobDetailBean"> 4 <property name="jobClass"> 5 <value>com.webservice.crs.newtask.CrrcSyncDataTimer</value> 6 </property> 7 </bean> 8 <!-- 增量同步配置定时时间 --> 9 <bean id="CrrcSyncTaskTrigger1" 10 class="org.springframework.scheduling.quartz.CronTriggerBean"> 11 <property name="jobDetail" ref="CrrcSyncTask1" /> 12 <property name="cronExpression"> 13 <value>0 0 0/1 * * ?</value> 14 </property> 15 </bean> 16 17 <!-- 触发器管理类 --> 18 <bean id="scheduler" 19 class="org.springframework.scheduling.quartz.SchedulerFactoryBean"> 20 <!-- 添加触发器 --> 21 <property name="triggers"> 22 <list> 23 <ref bean="CrrcSyncTaskTrigger1" /> 24 </list> 25 </property> 26 </bean>