快速业务通道

Spring Quartz如何动态配置时间(2) - 编程入门网

作者 佚名技术 来源 NET编程 浏览 发布时间 2012-06-15

Spring Quartz如何动态配置时间(2)

时间:2011-08-09

上回说到,我们的设置页面已经做好了,接下来就是将时间转换为Unix Cron Expression。

2) 将时间转换为Unix Cron Expression

需要ActionForm将页面表单数据映射到Action中,然后在Action中转换为cron expression:

1 SchedulerForm schedulerForm = (SchedulerForm) form; 2     String jobName = schedulerForm.getJobName(); 3     String cronExpression =  "" ; 4     String[] commonNeeds =  {schedulerForm.getSecond(), schedulerForm.getMinute(), schedulerForm.getHour()} ; 5     String[] monthlyNeeds =  {schedulerForm.getWeek(), schedulerForm.getDayOfMonth()} ; 6     String weeklyNeeds = schedulerForm.getDayOfWeek(); 7     String userDefinedNeeds = schedulerForm.getDate(); 8     String everyWhat = schedulerForm.getEveryWhat(); 9     // 得到时间规则 10     cronExpression = CronExpConversion.getCronExpression(everyWhat, commonNeeds, 11         monthlyNeeds, weeklyNeeds, userDefinedNeeds); 12 

Spring Quartzè?o??ˉì?????ê±??£¨2£?(2)

ê±??:2011-08-09

?ò?¨ò?á?ò??? 1??òààà′′|àí×a??1??ò£¨D′μ?2?ê?oüo? ?üó??íDD oùoù£?

1?? 2?? /** */ /** 3??* ò3??éè??×a?aUNIX cron expressions ×a??àà 4??* CronExpConversion 5?? */ 6?? public?? class??CronExpConversion?? { 7???? 8?????? /** */ /** 9??????* ò3??éè??×a?aUNIX cron expressions ×a????·¨ 10??????*??@param??everyWhat 11??????*??@param??commonNeeds °üਠsecond minute hour 12??????*??@param??monthlyNeeds °üਠμú????D??ú D??ú?? 13??????*??@param??weeklyNeeds??°üਠD??ú?? 14??????*??@param??userDefinedNeeds??°üà¨??ì?ê±??μ? 15??????*??@return??cron expression 16?????? */ 17??????public?? static??String convertDateToCronExp(String everyWhat, 18???????????? String[] commonNeeds, String[] monthlyNeeds, String weeklyNeeds, 19??????????????String userDefinedNeeds)?? { 20???????? String cronEx??=?? "" ; 21???????? String commons??=??commonNeeds[ 0 ]??+?? "?? "?? +??commonNeeds[ 1 ]??+?? "?? " 22??????????????????+??commonNeeds[ 2 ]??+?? "?? " ; 23???????? String dayOfWeek??=?? "" ; 24?????????? if??( " monthly " .equals(everyWhat))?? { 25??????????????//??eg.: 6#3 (day 6 = Friday and "#3" = the 3rd one in the 26??????????????//??month) 27??????????????dayOfWeek??=??monthlyNeeds[ 1 ] 28??????????????????????+??CronExRelated.specialCharacters 29???????????????????????????? .get(CronExRelated._THENTH)??+??monthlyNeeds[ 0 ]; 30???????????? cronEx??=??(commons 31??????????????????????+??CronExRelated.specialCharacters.get(CronExRelated._ANY) 32??????????????????????+?? "?? " 33??????????????????????+??CronExRelated.specialCharacters.get(CronExRelated._EVERY) 34??????????????????????+?? "?? "?? +??dayOfWeek??+?? "?? " ).trim(); 35??????????}?? else?? if??( " weekly " .equals(everyWhat))?? { 36???????????? dayOfWeek??=??

凌众科技专业提供服务器租用、服务器托管、企业邮局、虚拟主机等服务,公司网站:http://www.lingzhong.cn 为了给广大客户了解更多的技术信息,本技术文章收集来源于网络,凌众科技尊重文章作者的版权,如果有涉及你的版权有必要删除你的文章,请和我们联系。以上信息与文章正文是不可分割的一部分,如果您要转载本文章,请保留以上信息,谢谢!

分享到: 更多

Copyright ©1999-2011 厦门凌众科技有限公司 厦门优通互联科技开发有限公司 All rights reserved

地址(ADD):厦门软件园二期望海路63号701E(东南融通旁) 邮编(ZIP):361008

电话:0592-5908028 传真:0592-5908039 咨询信箱:web@lingzhong.cn 咨询OICQ:173723134

《中华人民共和国增值电信业务经营许可证》闽B2-20100024  ICP备案:闽ICP备05037997号