Cron表达式工具类

   Quartz调度框架里最大的亮点就是Cron表达式,他能灵活的表达任务计划周期,但由于它的语法复杂多变,要让用户去书写Cron表达式,则简直就好比要小姐从良是一样的难。所以才有了Cron表达式工具类,使用它可以通过接收一些必要参数自动输出一个标准的Cron表达式。废话不多说,亮剑看码:

Java代码  

  1. package com.yida.framework.base.util.quartz;  
  2.   
  3. import java.util.Date;  
  4.   
  5. import com.yida.framework.base.util.DateUtil;  
  6. import com.yida.framework.modules.po.TaskSchedule;  
  7. import com.yida.framework.modules.web.model.TaskScheduleModel;  
  8.   
  9. /** 
  10.  * @ClassName: CronUtil 
  11.  * @Description: Cron表达式工具类 
  12.  * @author Lanxiaowei(736031305@qq.com) 
  13.  * @date 2015年12月11日 上午10:12:18 
  14.  * 
  15.  */  
  16. public class CronUtil {  
  17.       
  18.     /** 
  19.      *  
  20.      *方法摘要:构建TaskSchedule实例 
  21.      *@param  taskScheduleModel 
  22.      *@return TaskSchedule 
  23.      */  
  24.     /** 
  25.      * 所选作业类型: 
  26.      * 1  -> 简单任务[一次或多次] 
  27.      * 2  -> 每天 
  28.      * 4  -> 每周 
  29.      * 8  -> 每月 
  30.      * 16 -> 每时间段 
  31.      * 32 -> 系统启动时 
  32.      */  
  33.     public static TaskSchedule createTaskSchedule(TaskSchedule taskSchedule,TaskScheduleModel taskScheduleModel){  
  34.         if(null == taskSchedule){  
  35.             taskSchedule = new TaskSchedule();  
  36.         }  
  37.         taskSchedule.setScheduleName(taskScheduleModel.getScheduleName());  
  38.         //计划执行开始时间  
  39.         Date startTime = taskScheduleModel.getScheduleStartTime();  
  40.         if(null != startTime){  
  41.             taskSchedule.setScheduleStartTime(startTime);  
  42.         }  
  43.           
  44.         //计划状态[默认:未运行]  
  45.         taskSchedule.setScheduleStatus(taskScheduleModel.getScheduleStatus());  
  46.           
  47.         //计划详细描述  
  48.         String description = createDescription(taskScheduleModel);  
  49.         taskSchedule.setScheduleDescription(description);  
  50.           
  51.         //简单任务  
  52.         if(taskScheduleModel.getJobType().intValue() == 1){  
  53.             //计划类型  
  54.             taskSchedule.setScheduleType(TaskSchedule.SCHEDULE_TYPE_SIMPLE);  
  55.             //计划延迟  
  56.             taskSchedule.setScheduleInterval(taskScheduleModel.getScheduleInterval());  
  57.             //计划重复执行次数  
  58.             taskSchedule.setScheduleRepeatCount(taskScheduleModel.getScheduleRepeatCount());  
  59.             taskSchedule.setScheduleStartTime(taskScheduleModel.getScheduleStartTime());  
  60.             taskSchedule.setScheduleEndTime(taskScheduleModel.getScheduleEndTime());  
  61.         }  
  62.         //系统启动时  
  63.         else if(taskScheduleModel.getJobType().intValue() == 64){  
  64.             //计划类型  
  65.             taskSchedule.setScheduleType(TaskSchedule.SCHEDULE_TYPE_WEB_STARTUP);  
  66.         }  
  67.         else {  
  68.             //Cron表达式  
  69.             String cron = createCronExpression(taskScheduleModel);  
  70.             taskSchedule.setScheduleCron(cron);  
  71.               
  72.             //计划类型  
  73.             taskSchedule.setScheduleType(TaskSchedule.SCHEDULE_TYPE_CRON);  
  74.         }  
  75.         return taskSchedule;  
  76.     }  
  77.       
  78.     /** 
  79.      *  
  80.      *方法摘要:构建Cron表达式 
  81.      *@param  taskScheduleModel 
  82.      *@return String 
  83.      */  
  84.     public static String createCronExpression(TaskScheduleModel taskScheduleModel){  
  85.         StringBuffer cronExp = new StringBuffer("");  
  86.           
  87.         //计划执行开始时间  
  88.         Date startTime = taskScheduleModel.getScheduleStartTime();  
  89.           
  90.         if(null != startTime){  
  91.             //秒  
  92.             cronExp.append(DateUtil.getSecond(startTime)).append(" ");  
  93.             //分  
  94.             cronExp.append(DateUtil.getMinute(startTime)).append(" ");  
  95.             //小时  
  96.             cronExp.append(DateUtil.getHourOfDay(startTime)).append(" ");  
  97.               
  98.             //按每天  
  99.             if(taskScheduleModel.getJobType().intValue() == 2){  
  100.                 //每工作日  
  101.                 if(taskScheduleModel.getEveryWeekDay().charValue() == '1'){  
  102.                     //一个月中第几天  
  103.                     cronExp.append("? ");  
  104.                     //月份  
  105.                     cronExp.append("* ");  
  106.                     //星期[星期一到星期五]  
  107.                     cronExp.append("2-6");  
  108.                 } else{  
  109.                     //一个月中第几天  
  110.                     cronExp.append("*/").append(taskScheduleModel.getIntervalDay()).append(" ");  
  111.                     //月份  
  112.                     cronExp.append("* ");  
  113.                     //星期  
  114.                     cronExp.append("?");  
  115.                 }  
  116.             }  
  117.               
  118.             //按每周  
  119.             else if(taskScheduleModel.getJobType().intValue() == 4){  
  120.                 //一个月中第几天  
  121.                 cronExp.append("? ");  
  122.                 //月份  
  123.                 cronExp.append("* ");  
  124.                 //周  
  125.                 Integer[] weeks = taskScheduleModel.getDayOfWeeks();  
  126.                 for(int i = 0; i < weeks.length; i++){  
  127.                     if(i == 0){  
  128.                         cronExp.append(weeks[i]);  
  129.                     } else{  
  130.                         cronExp.append(",").append(weeks[i]);  
  131.                     }  
  132.                 }  
  133.                   
  134.                 //每隔?周  
  135.                 if(taskScheduleModel.getIntervalWeek().intValue() > 0){  
  136.                     cronExp.append("/").append(taskScheduleModel.getIntervalWeek());  
  137.                 }  
  138.             }  
  139.               
  140.             //按每月  
  141.             else if(taskScheduleModel.getJobType().intValue() == 8){  
  142.                 //当前年份  
  143.                 int currentYear = DateUtil.getYear(startTime);  
  144.                 //当前月份  
  145.                 int currentMonth = DateUtil.getMonth(startTime);  
  146.                 //当前月份的最大天数  
  147.                 int maxDayOfMonth = DateUtil.getMaxDayOfMonth(currentYear, currentMonth);  
  148.                   
  149.                 //月份中具体某一天  
  150.                 if (null != taskScheduleModel.getWhichDay())  
  151.                 {  
  152.                     //如果所选日期数大于当月最大天数,则默认表示当月最后一天  
  153.                     if(taskScheduleModel.getWhichDay() > maxDayOfMonth){  
  154.                         cronExp.append("L ");  
  155.                     }  
  156.                     else{  
  157.                         cronExp.append(taskScheduleModel.getWhichDay()).append(" ");  
  158.                     }  
  159.                 } else{  
  160.                     cronExp.append("? ");  
  161.                 }  
  162.                   
  163.                 //指定多个月份  
  164.                 if(null != taskScheduleModel.getCountOfMonths()){  
  165.                     for(int i = 0; i < taskScheduleModel.getCountOfMonths().length; i++){  
  166.                         if(i == taskScheduleModel.getCountOfMonths().length - 1){  
  167.                             cronExp.append(taskScheduleModel.getCountOfMonths()[i]);  
  168.                         } else{  
  169.                             cronExp.append(taskScheduleModel.getCountOfMonths()[i]).append(",");  
  170.                         }  
  171.                     }  
  172.                     cronExp.append(" ");  
  173.                 } else{  
  174.                     cronExp.append("? ");  
  175.                 }  
  176.                   
  177.                 //当月第几周的周几  
  178.                 if(null == taskScheduleModel.getIntervalDayOfWeek() || taskScheduleModel.getIntervalDayOfWeek() == 0){  
  179.                     cronExp.append("? ");  
  180.                 } else if(taskScheduleModel.getIntervalDayOfWeek() > 4){  
  181.                     cronExp.append("L "); //超过4,表示当月最后一周  
  182.                 } else{  
  183.                     if(null == taskScheduleModel.getDayOfWeek()){  
  184.                         cronExp.append("*#").append(taskScheduleModel.getIntervalDayOfWeek());  
  185.                     } else{  
  186.                         cronExp.append(taskScheduleModel.getDayOfWeek()).append("#").append(taskScheduleModel.getIntervalDayOfWeek());  
  187.                     }  
  188.                 }  
  189.             }  
  190.               
  191.             //按间隔时间段  
  192.             else if(taskScheduleModel.getJobType().intValue() == 16){  
  193.                 cronExp = new StringBuffer("");  
  194.                 //秒  
  195.                 if(null == taskScheduleModel.getIntervalCountOfSecond() || taskScheduleModel.getIntervalCountOfSecond().intValue() == 0){  
  196.                     cronExp.append(DateUtil.getSecond(startTime)).append(" ");  
  197.                 } else{  
  198.                     cronExp.append(DateUtil.getSecond(startTime)).append("/");  
  199.                     cronExp.append(taskScheduleModel.getIntervalCountOfSecond()).append(" ");  
  200.                 }  
  201.                   
  202.                 //分  
  203.                 if(null == taskScheduleModel.getIntervalCountOfMinute() || taskScheduleModel.getIntervalCountOfMinute().intValue() == 0){  
  204.                     cronExp.append(DateUtil.getMinute(startTime)).append(" ");  
  205.                 } else{  
  206.                     cronExp.append(DateUtil.getMinute(startTime)).append("/");  
  207.                     cronExp.append(taskScheduleModel.getIntervalCountOfMinute()).append(" ");  
  208.                 }  
  209.                   
  210.                 //小时  
  211.                 if(null == taskScheduleModel.getIntervalCountOfHours() || taskScheduleModel.getIntervalCountOfHours().intValue() == 0){  
  212.                     cronExp.append(DateUtil.getHourOfDay(startTime)).append(" ");  
  213.                 } else{  
  214.                     cronExp.append(DateUtil.getHourOfDay(startTime)).append("/");  
  215.                     cronExp.append(taskScheduleModel.getIntervalCountOfHours()).append(" ");  
  216.                 }  
  217.                   
  218.                 //日期  
  219.                 if(null == taskScheduleModel.getIntervalCountOfDay() || taskScheduleModel.getIntervalCountOfDay().intValue() == 0){  
  220.                     cronExp.append(DateUtil.getDayOfMonth(startTime)).append(" ");  
  221.                 } else{  
  222.                     cronExp.append(DateUtil.getDayOfMonth(startTime)).append("/");  
  223.                     cronExp.append(taskScheduleModel.getIntervalCountOfDay()).append(" ");  
  224.                 }  
  225.                   
  226.                 //月  
  227.                 if(null == taskScheduleModel.getIntervalCountOfMonth() || taskScheduleModel.getIntervalCountOfMonth().intValue() == 0){  
  228.                     cronExp.append(DateUtil.getMonth(startTime)).append(" ");  
  229.                 } else{  
  230.                     cronExp.append(DateUtil.getMonth(startTime)).append("/");  
  231.                     cronExp.append(taskScheduleModel.getIntervalCountOfMonth());  
  232.                 }  
  233.             }  
  234.               
  235.             // 按特定时间点  
  236.             else if(taskScheduleModel.getJobType().intValue() == 32){  
  237.                 cronExp = new StringBuffer("* ");  
  238.                 if(taskScheduleModel.getMinituesOfHour() != null && taskScheduleModel.getMinituesOfHour().length > 0) {  
  239.                     int index = 0;  
  240.                     for(int minitue : taskScheduleModel.getMinituesOfHour()) {  
  241.                         if(index == taskScheduleModel.getMinituesOfHour().length - 1) {  
  242.                             cronExp.append(minitue);  
  243.                         } else {  
  244.                             cronExp.append(minitue).append(",");  
  245.                         }  
  246.                         index++;  
  247.                     }  
  248.                 }  
  249.                 if(taskScheduleModel.getHoursOfDay() != null && taskScheduleModel.getHoursOfDay().length > 0) {  
  250.                     if(taskScheduleModel.getMinituesOfHour() != null && taskScheduleModel.getMinituesOfHour().length > 0) {  
  251.                         cronExp.append(" ");  
  252.                     }  
  253.                     int index = 0;  
  254.                     for(int hour : taskScheduleModel.getHoursOfDay()) {  
  255.                         if(index == taskScheduleModel.getHoursOfDay().length - 1) {  
  256.                             cronExp.append(hour);  
  257.                         } else {  
  258.                             cronExp.append(hour).append(",");  
  259.                         }  
  260.                         index++;  
  261.                     }  
  262.                 }  
  263.                 cronExp.append(" * * *");  
  264.             }  
  265.         }  
  266.         return cronExp.toString();  
  267.     }  
  268.       
  269.     /** 
  270.      *  
  271.      *方法摘要:生成计划的详细描述 
  272.      *@param  taskScheduleModel 
  273.      *@return String 
  274.      */  
  275.     public static String createDescription(TaskScheduleModel taskScheduleModel){  
  276.         StringBuffer description = new StringBuffer("");  
  277.         //简单任务  
  278.         if(taskScheduleModel.getJobType().intValue() == 1){  
  279.             description.append("简单任务,延迟(ms):");  
  280.             description.append(taskScheduleModel.getScheduleInterval());  
  281.             if(taskScheduleModel.getScheduleRepeatCount() <= 0) {  
  282.                 description.append(",执行次数:无限制,永远循环执行下去。");  
  283.             } else {  
  284.                 description.append(",重复执行次数:");  
  285.                 description.append(taskScheduleModel.getScheduleRepeatCount());  
  286.             }  
  287.         }  
  288.         //系统启动时  
  289.         else if(taskScheduleModel.getJobType().intValue() == 64){  
  290.             description.append("系统启动时执行");  
  291.         }  
  292.         else{  
  293.             //计划执行开始时间  
  294.             Date startTime = taskScheduleModel.getScheduleStartTime();  
  295.               
  296.             if(null != startTime){  
  297.                 //按每天  
  298.                 if(taskScheduleModel.getJobType().intValue() == 2){  
  299.                     //每工作日  
  300.                     if(taskScheduleModel.getEveryWeekDay().charValue() == '1'){  
  301.                         description.append("从").append(DateUtil.parseDate(startTime, "yyyy-MM-dd"));  
  302.                         description.append("起,于每个工作日").append(DateUtil.parseDate(startTime, "HH:mm:ss"));  
  303.                         description.append("执行");  
  304.                     } else{  
  305.                         //每天  
  306.                         if(taskScheduleModel.getIntervalDay().intValue() == 0){  
  307.                             description.append("从").append(DateUtil.parseDate(startTime, "yyyy-MM-dd"));  
  308.                             description.append("起,于每天").append(DateUtil.parseDate(startTime, "HH:mm:ss"));  
  309.                             description.append("执行");  
  310.                         }   
  311.                         //每间隔?天  
  312.                         else{  
  313.                             description.append("从").append(DateUtil.parseDate(startTime, "yyyy-MM-dd"));  
  314.                             description.append("起,每隔").append(taskScheduleModel.getIntervalDay()).append("天,于");  
  315.                             description.append(DateUtil.parseDate(startTime, "HH:mm:ss"));  
  316.                             description.append("执行");  
  317.                         }  
  318.                     }  
  319.                 }  
  320.                   
  321.                 //按每周  
  322.                 else if(taskScheduleModel.getJobType().intValue() == 4){  
  323.                     if(startTime != null) {  
  324.                         description.append("从").append(DateUtil.parseDate(startTime, "yyyy-MM-dd"));  
  325.                         description.append("起");  
  326.                     }  
  327.                     //每隔?周  
  328.                     if(taskScheduleModel.getIntervalWeek().intValue() > 0){  
  329.                         description.append(",每隔").append(taskScheduleModel.getIntervalWeek()).append("周");  
  330.                     }  
  331.                     if(taskScheduleModel.getDayOfWeeks() != null && taskScheduleModel.getDayOfWeeks().length > 0) {  
  332.                         description.append(",于每周的").append(DateUtil.getWeekString(taskScheduleModel.getDayOfWeeks())).append(" ");  
  333.                     }  
  334.                     if(startTime != null) {  
  335.                         description.append(" ,").append(DateUtil.parseDate(startTime, "HH:mm:ss"));   
  336.                     }  
  337.                     description.append("执行");  
  338.                 }  
  339.                   
  340.                 //按每月  
  341.                 else if(taskScheduleModel.getJobType().intValue() == 8){  
  342.                     description.append("从").append(DateUtil.parseDate(startTime, "yyyy-MM-dd"));  
  343.                       
  344.                     //选择月份  
  345.                     if(null != taskScheduleModel.getCountOfMonths() && taskScheduleModel.getCountOfMonths().length != 0){  
  346.                         description.append("起,于");  
  347.                         description.append(DateUtil.getMonthString(taskScheduleModel.getCountOfMonths()));  
  348.                     } else{  
  349.                         description.append("起,于每月的");  
  350.                         if(null != taskScheduleModel.getWhichDay() && taskScheduleModel.getWhichDay().intValue() != 0){  
  351.                             //当前年份  
  352.                             int currentYear = DateUtil.getYear(startTime);  
  353.                             //当前月份  
  354.                             int currentMonth = DateUtil.getMonth(startTime);  
  355.                             //当前月份的最大天数  
  356.                             int maxDayOfMonth = DateUtil.getMaxDayOfMonth(currentYear, currentMonth);  
  357.                             if(taskScheduleModel.getWhichDay() > maxDayOfMonth){  
  358.                                 description.append("最后一天");  
  359.                             } else{  
  360.                                 description.append(taskScheduleModel.getWhichDay()).append("号");  
  361.                             }  
  362.                         }   
  363.                     }  
  364.                       
  365.                     //第几个星期  
  366.                     if(null != taskScheduleModel.getIntervalDayOfWeek() && taskScheduleModel.getIntervalDayOfWeek().intValue() != 0){  
  367.                         if(taskScheduleModel.getIntervalDayOfWeek() > 4){  
  368.                             description.append("最后一个星期");  
  369.                         } else{  
  370.                             description.append("第").append(taskScheduleModel.getIntervalDayOfWeek());  
  371.                             description.append("个星期");  
  372.                         }  
  373.                     }  
  374.                       
  375.                     //星期几  
  376.                     if(null != taskScheduleModel.getDayOfWeek() && taskScheduleModel.getDayOfWeek().intValue() != 0){  
  377.                         description.append("的").append(DateUtil.getWeekString(taskScheduleModel.getDayOfWeek()));  
  378.                     } else{  
  379.                         description.append("的每天");  
  380.                     }  
  381.                     description.append(DateUtil.parseDate(startTime, "HH:mm:ss"));  
  382.                     description.append("执行");  
  383.                 }  
  384.                   
  385.                 //按每间隔时间段  
  386.                 else if(taskScheduleModel.getJobType().intValue() == 16){  
  387.                     //没填写间隔信息  
  388.                     if((null == taskScheduleModel.getIntervalCountOfSecond() || taskScheduleModel.getIntervalCountOfSecond().intValue() == 0) &&  
  389.                         (null == taskScheduleModel.getIntervalCountOfMinute() || taskScheduleModel.getIntervalCountOfMinute().intValue() == 0) &&  
  390.                         (null == taskScheduleModel.getIntervalCountOfHours() || taskScheduleModel.getIntervalCountOfHours().intValue() == 0) &&  
  391.                         (null == taskScheduleModel.getIntervalCountOfDay() || taskScheduleModel.getIntervalCountOfDay().intValue() == 0) &&  
  392.                         (null == taskScheduleModel.getIntervalCountOfMonth() || taskScheduleModel.getIntervalCountOfMonth().intValue() == 0)   
  393.                     ){  
  394.                         description.append("从").append(DateUtil.parseDate(startTime, "yyyy-MM-dd"));  
  395.                         description.append("起,于");  
  396.                         description.append(DateUtil.parseDate(startTime, "HH:mm:ss"));  
  397.                         description.append("执行一次");  
  398.                     } else{  
  399.                         //秒  
  400.                         if(null != taskScheduleModel.getIntervalCountOfSecond() && taskScheduleModel.getIntervalCountOfSecond().intValue() != 0){  
  401.                             description.append("从").append(DateUtil.parseDate(startTime, "yyyy-MM-dd"));  
  402.                             description.append("起,每隔");  
  403.                             description.append(taskScheduleModel.getIntervalCountOfSecond()).append("秒,于");  
  404.                             description.append(DateUtil.parseDate(startTime, "HH:mm:ss"));  
  405.                             description.append("执行");  
  406.                         }  
  407.                         //分  
  408.                         if(null != taskScheduleModel.getIntervalCountOfMinute() && taskScheduleModel.getIntervalCountOfMinute().intValue() != 0){  
  409.                             description.append("从").append(DateUtil.parseDate(startTime, "yyyy-MM-dd"));  
  410.                             description.append("起,每隔");  
  411.                             description.append(taskScheduleModel.getIntervalCountOfMinute()).append("分钟,于");  
  412.                             description.append(DateUtil.parseDate(startTime, "HH:mm:ss"));  
  413.                             description.append("执行");  
  414.                         }  
  415.                         //小时  
  416.                         if(null != taskScheduleModel.getIntervalCountOfHours() && taskScheduleModel.getIntervalCountOfHours().intValue() != 0){  
  417.                             description.append("从").append(DateUtil.parseDate(startTime, "yyyy-MM-dd"));  
  418.                             description.append("起,每隔");  
  419.                             description.append(taskScheduleModel.getIntervalCountOfHours()).append("小时,于");  
  420.                             description.append(DateUtil.parseDate(startTime, "HH:mm:ss"));  
  421.                             description.append("执行");  
  422.                         }  
  423.                         //日  
  424.                         if(null != taskScheduleModel.getIntervalCountOfDay() && taskScheduleModel.getIntervalCountOfDay().intValue() != 0){  
  425.                             description.append("从").append(DateUtil.parseDate(startTime, "yyyy-MM-dd"));  
  426.                             description.append("起,每隔");  
  427.                             description.append(taskScheduleModel.getIntervalCountOfDay()).append("天,于");  
  428.                             description.append(DateUtil.parseDate(startTime, "HH:mm:ss"));  
  429.                             description.append("执行");  
  430.                         }  
  431.                         //月  
  432.                         if(null != taskScheduleModel.getIntervalCountOfMonth() && taskScheduleModel.getIntervalCountOfMonth().intValue() != 0){  
  433.                             description.append("从").append(DateUtil.parseDate(startTime, "yyyy-MM-dd"));  
  434.                             description.append("起,每隔");  
  435.                             description.append(taskScheduleModel.getIntervalCountOfMonth()).append("个月,于");  
  436.                             description.append(DateUtil.parseDate(startTime, "HH:mm:ss"));  
  437.                             description.append("执行");  
  438.                         }  
  439.                     }  
  440.                 }  
  441.                   
  442.                 //按特定时间点  
  443.                 else if(taskScheduleModel.getJobType().intValue() == 32){  
  444.                     if(startTime != null) {  
  445.                         description.append("从").append(DateUtil.parseDate(startTime, "yyyy-MM-dd HH:mm:ss"));  
  446.                         description.append("起开始执行");  
  447.                     }  
  448.                     if(taskScheduleModel.getHoursOfDay() != null && taskScheduleModel.getHoursOfDay().length > 0) {  
  449.                         int index = 0;  
  450.                         description.append(",此后于每天的");  
  451.                         for(int hour : taskScheduleModel.getHoursOfDay()) {  
  452.                             if(index == taskScheduleModel.getHoursOfDay().length - 1) {  
  453.                                 description.append(hour + 1).append("点");  
  454.                             } else {  
  455.                                 description.append(hour + 1).append("点,");  
  456.                             }  
  457.                             index++;  
  458.                         }  
  459.                     }  
  460.                     if(taskScheduleModel.getMinituesOfHour() != null && taskScheduleModel.getMinituesOfHour().length > 0) {  
  461.                         int index = 0;  
  462.                         description.append(",");  
  463.                         for(int minitue : taskScheduleModel.getMinituesOfHour()) {  
  464.                             if(index == taskScheduleModel.getMinituesOfHour().length - 1) {  
  465.                                 description.append(minitue + 1).append("分");  
  466.                             } else {  
  467.                                 description.append(minitue + 1).append("分,");  
  468.                             }  
  469.                             index++;  
  470.                         }  
  471.                     }  
  472.                     description.append("定时执行");  
  473.                 }  
  474.             }  
  475.         }  
  476.         return description.toString();  
  477.     }  
  478. }  

转载:http://iamyida.iteye.com/blog/2263338

时间: 2025-01-29 08:10:54

Cron表达式工具类的相关文章

Pig系统分析(7) Pig实用工具类

Explain Explain是Pig提供的调试工具,使用explain可以输出Pig Lation的执行计划.值得一提的是,explain支持-dot选项,将执行计划以DOT格式输出, (DOT是一种图形描述语言,请参考http://zh.wikipedia.org/zh/DOT%E8%AF%AD%E8%A8%80) 代码实现详见org.apache.pig.impl.plan.DotPlanDumper,这部分实现为我们设计执行计划可视化提供了参考. 下图部分截取了使用Graphviz打开物

Spring集成Quartz定时任务框架介绍和Cron表达式详解

原文地址:http://www.cnblogs.com/obullxl/archive/2011/07/10/spring-quartz-cron-integration.html 在JavaEE系统中,我们会经常用到定时任务,比如每天凌晨生成前天报表,每一小时生成汇总数据等等.我们可以使用java.util.Timer结合java.util.TimerTask来完成这项工作,但时调度控制非常不方便,并且我们需要大量的代码.使用Quartz框架无疑是非常好的选择,并且与Spring可以非常方便的

源码剖析AQS在几个同步工具类中的使用

感谢网友[张超盟]的投稿 1. 前言 AQS(AbstractQueuedSynchronizer)是 java.util.concurrent的基础.J.U.C中宣传的封装良好的同步工具类Semaphore.CountDownLatch.ReentrantLock.ReentrantReadWriteLock.FutureTask等虽然各自都有不同特征,但是简单看一下源码,每个类内部都包含一个如下的内部类定义: abstract static class Sync extends Abstra

SpringBoot定时任务及Cron表达式详解

摘要: 讲解如何使用SpringBoot定时任务,并通过源码说明如何使用多线程处理各定时任务. 详细说明cron表达式用法. 一.定时任务概述 后台项目开发中经常会用到定时任务,现在实现定时任务都方式也是多种多样.下面列举几种常见的定时任务实现方式: 1. Quartz:Quartz的使用相当广泛,它是一个功能强大的调度器,当然使用起来也相对麻烦; 2. java.util包里的Timer,它也可以实现定时任务但是功能过于单一所有使用很少. 3. 就是我们今天要介绍的Spring自带的定时任务S

Cron表达式

(1).Cron表达式在线生成网站   (2).cron表达式测试工具 源码地址:http://download.csdn.net/download/xushaonian/5790307   (3).Quartz Cron生成工具 http://www.cnblogs.com/haiconc/archive/2013/11/04/3407209.html    关于cron表达式的解释说明: http://blog.csdn.net/feiyun72/article/details/692136

(2)Spring集成Quartz定时任务框架介绍和Cron表达式详解

在JavaEE系统中,我们会经常用到定时任务,比如每天凌晨生成前天报表,每一小时生成汇总数据等等.我们可以使用java.util.Timer结合java.util.TimerTask来完成这项工作,但时调度控制非常不方便,并且我们需要大量的代码.使用Quartz框架无疑是非常好的选择,并且与Spring可以非常方便的集成,下面介绍它们集成方法和Cron表达式的详细介绍. 一.增加所依赖的JAR包1.增加Spring的Maven依赖 <dependency><groupId>org.

Quartz.NET总结(二)CronTrigger和Cron表达式

Quartz.NET的任务调度,主要就是依靠CronTrigger和Cron表达式.Cron是已经在UNIX存在了很长一段时间,它有着强大和可靠的调度能力.CronTrigger类也正是是基于Cron调度能力. CronTrigger使用Cron表达式.它能灵活的设置各种计划任务,比如每周一至周五,早上8点执行某项任务.然而虽然Cron表达式功能强大,灵活,但是也很混乱难懂.所以便在这里介绍Cron表达式相关的配置.希望大家帮助大家快速理解. Cron格式 Cron表达式被用来配置CronTri

android自动工具类TextUtils使用详解

今天,简单讲讲如何使用android自动的工具类TextUtils. 简单列举部分用法: Log.d(TAG, "---------------------------------"); //字符串拼接 Log.d(TAG, TextUtils.concat("Hello", " ", "world!").toString()); //判断是否为空字符串 Log.d(TAG, TextUtils.isEmpty("H

文件系统扫描的工具类

文件系统扫描的工具类   说明 递归扫描文件夹系统,并以树形结构组织起来 支持沙盒.bundle扫描 支持扫描深度设置 用File对象表示一个扫描出来的文件,File对象包含了一个文件或者文件夹的基本文件信息(如文件名字,是否隐藏,文件扩展名,文件url地址等等),便于后续操作 源码 https://github.com/YouXianMing/iOS-Utilities // // ViewController.m // FileManager // // Created by YouXian