代码语言
.
CSharp
.
JS
Java
Asp.Net
C
MSSQL
PHP
Css
PLSQL
Python
Shell
EBS
ASP
Perl
ObjC
VB.Net
VBS
MYSQL
GO
Delphi
AS
DB2
Domino
Rails
ActionScript
Scala
代码分类
文件
系统
字符串
数据库
网络相关
图形/GUI
多媒体
算法
游戏
Jquery
Extjs
Android
HTML5
菜单
网页交互
WinForm
控件
企业应用
安全与加密
脚本/批处理
开放平台
其它
【
Java
】
quartz的工具类
作者:
文华
/ 发布于
2017/1/11
/
789
cache类: package com.sitech.message.base; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; import org.quartz.Scheduler; /** * 系统缓存,建议换redis * @author hb */ public class Cache { /** * scheduler 缓存 */ public static Map<String,Scheduler> scheduler_task = new ConcurrentHashMap<String,Scheduler>(); /** * job 缓存 */ public static Map<String,String> scheduler_task_job = new ConcurrentHashMap<String,String>(); /** * 获取规则 * */ public static Map<String,Object> task_size = new ConcurrentHashMap<String,Object>(); } package com.sitech.message.controller.task; import java.util.Calendar; import java.util.HashMap; import java.util.List; import java.util.Map; import org.apache.commons.lang.StringUtils; import org.apache.log4j.Logger; import org.quartz.JobDataMap; import org.quartz.JobDetail; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Component; import com.sitech.message.base.Cache; import com.sitech.message.dao.BaseDao; import com.sitech.message.dao.NameSpace; import com.sitech.message.job.WarningDept; import com.sitech.message.job.WarningQuestion; import com.sitech.message.service.IQuartzTaskService; /** * 预警 * @author Administrator * */ @Component public class JobWarningSchedular { private static final Logger logger = Logger.getLogger(JobWarningSchedular.class); @Autowired private BaseDao baseDao; @Autowired private IQuartzTaskService quartzTaskService; private boolean isFirst = true; /** * 预警扫描 */ @Scheduled(cron = "0 0/1 * * * ?") public void scan(){ logger.debug("start scan... time:"+Calendar.getInstance().getTime()); Map<String,String> paramMap = new HashMap<String,String>(); if(!isFirst){ paramMap.put("is_update", "1"); } paramMap.put("type", "2"); //从配置文件取数据 List<Map<String,Object>> configs = baseDao.selectList(NameSpace.BS_JOB_WARNINGMapper, "selective",paramMap); System.out.println(configs.size()); for(Map<String,Object> config : configs){ String id = (String) config.get("ID"); String type = (String)config.get("TYPE"); String classify = (String)config.get("CLASSIFY"); String job_dept = id+"_"+type+"_"+classify+"_dept"; String job_question = id+"_"+type+"_"+classify+"_question"; String is_warn = (String)config.get("IS_WARN"); //扫描时间 String cron_m0 = (String)config.get("CRON_M0"); String cron_m1 = (String)config.get("CRON_M1"); String cron_m2 = (String)config.get("CRON_M2"); //如果是第一次扫描,全部扫描 if(isFirst){ //is_warn为0,执行预警扫描. if("0".equals(is_warn)){ //部门预警 if(StringUtils.isEmpty(Cache.scheduler_task_job.get(job_dept))){ JobDetail jobDetail = new JobDetail(job_dept, job_dept, WarningDept.class); //如果部门为空,默认本地网cron_m0 if(StringUtils.isEmpty(cron_m1)){ cron_m1 = cron_m0; } JobDataMap map = new JobDataMap(); map.putAll(config); jobDetail.setJobDataMap(map); Cache.scheduler_task_job.put(job_dept, job_dept); quartzTaskService.addJob(job_dept, jobDetail , WarningDept.class, cron_m1); } //整单预警 if(StringUtils.isEmpty(Cache.scheduler_task_job.get(job_question))){ JobDetail jobDetail = new JobDetail(job_question, job_question, WarningQuestion.class); JobDataMap map = new JobDataMap(); map.putAll(config); jobDetail.setJobDataMap(map); Cache.scheduler_task_job.put(job_question, job_question); quartzTaskService.addJob(job_question, jobDetail , WarningQuestion.class, cron_m2); } } }else{//专门用于更新扫描操作,两步操作 //1.先删除预警线程,然后增加新的预警线程 //部门预警的线程操作 if(job_dept.equals(Cache.scheduler_task_job.get(job_dept))){ logger.debug("delte job_dept...."); Cache.scheduler_task_job.remove(job_dept); quartzTaskService.removeJob(job_dept); } //整单预警的线程操作 if(job_question.equals(Cache.scheduler_task_job.get(job_question))){ logger.debug("delete job_question..."); Cache.scheduler_task_job.remove(job_question); quartzTaskService.removeJob(job_question); } if("0".equals(is_warn)){ logger.debug("delte job_dept...."); JobDetail jobDetail = new JobDetail(job_dept, job_dept, WarningDept.class); //如果部门为空,默认本地网cron_m0 if(StringUtils.isEmpty(cron_m1)){ cron_m1 = cron_m0; } JobDataMap map = new JobDataMap(); map.putAll(config); jobDetail.setJobDataMap(map); logger.debug("add new job_dept...."); Cache.scheduler_task_job.put(job_dept, job_dept); quartzTaskService.addJob(job_dept, jobDetail , WarningDept.class, cron_m1); JobDetail jobDetail1 = new JobDetail(job_question, job_question, WarningQuestion.class); jobDetail1.setJobDataMap(map); logger.debug("add job_question..."); Cache.scheduler_task_job.put(job_question, job_question); quartzTaskService.addJob(job_question, jobDetail1 , WarningQuestion.class, cron_m2); } try { baseDao.update(NameSpace.BS_JOB_WARNINGMapper, "updateStatus", config); } catch (Exception e) { logger.error("update bs_job_warning is failed ",e); } } } isFirst = false; logger.debug("end scan... time:"+Calendar.getInstance().getTime()); } }
试试其它关键字
同语言下
.
List 切割成几份 工具类
.
一行一行读取txt的内容
.
Java PDF转换成图片并输出给前台展示
.
java 多线程框架
.
double类型如果小数点后为零则显示整数否则保留两位小
.
将图片转换为Base64字符串公共类抽取
.
sqlParser 处理SQL(增删改查) 替换schema 用于多租户
.
JAVA 月份中的第几周处理 1-7属于第一周 依次类推 29-
.
java计算两个经纬度之间的距离
.
输入时间参数计算年龄
可能有用的
.
List 切割成几份 工具类
.
一行一行读取txt的内容
.
Java PDF转换成图片并输出给前台展示
.
java 多线程框架
.
double类型如果小数点后为零则显示整数否则保留两位小
.
将图片转换为Base64字符串公共类抽取
.
sqlParser 处理SQL(增删改查) 替换schema 用于多租户
.
JAVA 月份中的第几周处理 1-7属于第一周 依次类推 29-
.
java计算两个经纬度之间的距离
.
输入时间参数计算年龄
文华
贡献的其它代码
(
11
)
.
用net匹配并替换iOS标准的emoji表情符号
.
html5将文字生成图片
.
quartz的工具类
.
倒计时弹出框
.
使用Jedis操作Redis
.
最小生成树算法
.
解决POST和GET编码问题
.
微信 关注数量的代码
.
android去掉标题的做法
.
android实现音频文件播放的方法
Copyright © 2004 - 2024 dezai.cn. All Rights Reserved
站长博客
粤ICP备13059550号-3