From e67870fff62635cd14beb0d5988f08aeef4b22fa Mon Sep 17 00:00:00 2001 From: zhubaomin <zhubaomin> Date: 星期一, 07 四月 2025 21:27:06 +0800 Subject: [PATCH] 添加远程关阀式终止灌溉计划,未测试 --- pipIrr-platform/pipIrr-common/src/main/java/com/dy/common/schedulerTask/SchedulerTaskFactory.java | 80 ++++++++++++++++++++++++++++++++++++++++ 1 files changed, 80 insertions(+), 0 deletions(-) diff --git a/pipIrr-platform/pipIrr-common/src/main/java/com/dy/common/schedulerTask/SchedulerTaskFactory.java b/pipIrr-platform/pipIrr-common/src/main/java/com/dy/common/schedulerTask/SchedulerTaskFactory.java new file mode 100644 index 0000000..3b19a91 --- /dev/null +++ b/pipIrr-platform/pipIrr-common/src/main/java/com/dy/common/schedulerTask/SchedulerTaskFactory.java @@ -0,0 +1,80 @@ +package com.dy.common.schedulerTask; + +import java.util.Properties; + +import org.apache.logging.log4j.*; +import org.quartz.Scheduler; +import org.quartz.SchedulerException; +import org.quartz.impl.StdSchedulerFactory; + +public class SchedulerTaskFactory { + + private static Logger log = LogManager.getLogger(SchedulerTaskFactory.class.getName()) ; + + private static Scheduler scheduler ; + + private static Properties pro ; + + static{ + pro = new Properties() ; + //浠ヤ笅灞炴�т粠quartz-all-2.1.7.jar寰楀埌锛岃�屼笖涓嬮潰鎵�鏈夐」鐩兘瑕侀厤缃� + pro.put("org.quartz.scheduler.instanceName", "DefaultQuartzScheduler"); + pro.put("org.quartz.scheduler.rmi.export", "false"); + pro.put("org.quartz.scheduler.rmi.proxy", "false"); + pro.put("org.quartz.scheduler.wrapJobExecutionInUserTransaction", "false"); + pro.put("org.quartz.threadPool.class", "org.quartz.simpl.SimpleThreadPool"); + pro.put("org.quartz.threadPool.threadCount", "10"); + pro.put("org.quartz.threadPool.threadPriority", "5"); + pro.put("org.quartz.threadPool.threadsInheritContextClassLoaderOfInitializingThread", "true"); + pro.put("org.quartz.jobStore.misfireThreshold", "60000"); + pro.put("org.quartz.jobStore.class", "org.quartz.simpl.RAMJobStore"); + } + + /** + * 寰楀埌璋冨害鍣ㄥ敮涓�瀹炰緥 + * @return + */ + public static Scheduler getSingleScheduler(){ + if(scheduler == null){ + try { + scheduler = new StdSchedulerFactory(pro).getScheduler(); + } catch (SchedulerException e) { + log.error(e) ; + } + } + return scheduler ; + } + + + /** + * 寰楀埌璋冨害鍣ㄥ敮涓�瀹炰緥 + * @param threadPoolMaxCount + * @param threadPoolPriority + * @return + */ + public static Scheduler getSingleScheduler(Integer threadPoolMaxCount, Integer threadPoolPriority){ + if(scheduler == null){ + try { + if(threadPoolMaxCount != null && threadPoolMaxCount.intValue() >= 0){ + pro.put("org.quartz.threadPool.threadCount", "" + (threadPoolMaxCount==null?10:(threadPoolMaxCount<=0?10:threadPoolMaxCount))); + } + if(threadPoolPriority != null && threadPoolPriority.intValue() >= 0){ + pro.put("org.quartz.threadPool.threadPriority", "" + (threadPoolPriority==null?5:(threadPoolPriority<=0?5:threadPoolPriority))); + } + scheduler = new StdSchedulerFactory(pro).getScheduler(); + } catch (SchedulerException e) { + log.error(e) ; + } + } + return scheduler ; + } + + /** + * 鍏抽棴璋冨害鍣� + * @throws SchedulerException + */ + public static void shutdownScheduler() throws SchedulerException{ + scheduler.shutdown() ; + } + +} -- Gitblit v1.8.0