重构调度服务注入方式

master
xueli.xue 9 years ago
parent d81b0749a6
commit 0f0906eeaf
  1. 32
      xxl-job-admin/src/main/java/com/xxl/job/core/util/DynamicSchedulerUtil.java
  2. 4
      xxl-job-admin/src/main/java/com/xxl/job/service/job/impl/DemoConcurrentJobBean.java
  3. 4
      xxl-job-admin/src/main/java/com/xxl/job/service/job/impl/DemoNomalJobBean.java

@ -8,8 +8,6 @@ import java.util.List;
import java.util.Map;
import java.util.Set;
import javax.annotation.Resource;
import org.quartz.CronScheduleBuilder;
import org.quartz.CronTrigger;
import org.quartz.Job;
@ -27,7 +25,10 @@ import org.quartz.impl.matchers.GroupMatcher;
import org.quartz.impl.triggers.CronTriggerImpl;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.util.Assert;
import com.xxl.job.client.util.JacksonUtil;
@ -39,32 +40,30 @@ import com.xxl.job.dao.IXxlJobLogDao;
* base quartz scheduler util
* @author xuxueli 2015-12-19 16:13:53
*/
public final class DynamicSchedulerUtil implements InitializingBean {
public final class DynamicSchedulerUtil implements ApplicationContextAware, InitializingBean {
private static final Logger logger = LoggerFactory.getLogger(DynamicSchedulerUtil.class);
// xxlJobLogDao
public static IXxlJobLogDao xxlJobLogDao;
@Resource
public void setXxlJobLogDao(IXxlJobLogDao xxlJobLogDao) {
DynamicSchedulerUtil.xxlJobLogDao = xxlJobLogDao;
}
// xxlJobInfoDao
public static IXxlJobInfoDao xxlJobInfoDao;
@Resource
public void setXxlJobInfoDao(IXxlJobInfoDao xxlJobInfoDao) {
DynamicSchedulerUtil.xxlJobInfoDao = xxlJobInfoDao;
}
// Scheduler
private static Scheduler scheduler;
public static void setScheduler(Scheduler scheduler) {
DynamicSchedulerUtil.scheduler = scheduler;
}
// xxlJobLogDao、xxlJobInfoDao
public static IXxlJobLogDao xxlJobLogDao;
public static IXxlJobInfoDao xxlJobInfoDao;
@Override
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
DynamicSchedulerUtil.xxlJobLogDao = applicationContext.getBean(IXxlJobLogDao.class);
DynamicSchedulerUtil.xxlJobInfoDao = applicationContext.getBean(IXxlJobInfoDao.class);
}
@Override
public void afterPropertiesSet() throws Exception {
Assert.notNull(scheduler, "quartz scheduler is null");
logger.info(">>>>>>>>> init quartz scheduler success.[{}]", scheduler);
}
// getJobKeys
@ -266,4 +265,5 @@ public final class DynamicSchedulerUtil implements InitializingBean {
return result;
}
}

@ -6,6 +6,10 @@ import org.quartz.DisallowConcurrentExecution;
import com.xxl.job.service.job.LocalNomalJobBean;
/**
* demo job bean for no-concurrent
* @author xuxueli 2016-3-12 14:25:14
*/
@DisallowConcurrentExecution // 串行;线程数要多配置几个,否则不生效;
public class DemoConcurrentJobBean extends LocalNomalJobBean {

@ -7,6 +7,10 @@ import org.slf4j.LoggerFactory;
import com.xxl.job.service.job.LocalNomalJobBean;
/**
* demo job bean for concurrent
* @author xuxueli 2016-3-12 14:25:57
*/
public class DemoNomalJobBean extends LocalNomalJobBean {
private static Logger Logger = LoggerFactory.getLogger(DemoNomalJobBean.class);

Loading…
Cancel
Save