From 0f0906eeaffe6196ab1c1c62d4c67b7642221346 Mon Sep 17 00:00:00 2001 From: "xueli.xue" Date: Sat, 12 Mar 2016 14:36:57 +0800 Subject: [PATCH] =?UTF-8?q?=E9=87=8D=E6=9E=84=E8=B0=83=E5=BA=A6=E6=9C=8D?= =?UTF-8?q?=E5=8A=A1=E6=B3=A8=E5=85=A5=E6=96=B9=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../job/core/util/DynamicSchedulerUtil.java | 32 +++++++++---------- .../job/impl/DemoConcurrentJobBean.java | 4 +++ .../service/job/impl/DemoNomalJobBean.java | 4 +++ 3 files changed, 24 insertions(+), 16 deletions(-) diff --git a/xxl-job-admin/src/main/java/com/xxl/job/core/util/DynamicSchedulerUtil.java b/xxl-job-admin/src/main/java/com/xxl/job/core/util/DynamicSchedulerUtil.java index f87f5887..1b06f653 100644 --- a/xxl-job-admin/src/main/java/com/xxl/job/core/util/DynamicSchedulerUtil.java +++ b/xxl-job-admin/src/main/java/com/xxl/job/core/util/DynamicSchedulerUtil.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; } + } \ No newline at end of file diff --git a/xxl-job-admin/src/main/java/com/xxl/job/service/job/impl/DemoConcurrentJobBean.java b/xxl-job-admin/src/main/java/com/xxl/job/service/job/impl/DemoConcurrentJobBean.java index 9c4c9322..678347c8 100644 --- a/xxl-job-admin/src/main/java/com/xxl/job/service/job/impl/DemoConcurrentJobBean.java +++ b/xxl-job-admin/src/main/java/com/xxl/job/service/job/impl/DemoConcurrentJobBean.java @@ -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 { diff --git a/xxl-job-admin/src/main/java/com/xxl/job/service/job/impl/DemoNomalJobBean.java b/xxl-job-admin/src/main/java/com/xxl/job/service/job/impl/DemoNomalJobBean.java index 2541c2b5..66b6e3a4 100644 --- a/xxl-job-admin/src/main/java/com/xxl/job/service/job/impl/DemoNomalJobBean.java +++ b/xxl-job-admin/src/main/java/com/xxl/job/service/job/impl/DemoNomalJobBean.java @@ -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);