Jfinal quartz 2.2.1 plug-in

Source: Internet
Author: User

I wrote one by myself referring to Ext. version 2.2.1 runs OK and only relies on quartz and log4j, which is relatively simple.

Package COM. forg. plugin; import Java. io. ioexception; import Java. io. inputstream; import Java. util. enumeration; import Java. util. properties; import Org. quartz. cronschedulebuilder; import Org. quartz. crontrigger; import Org. quartz. job; import Org. quartz. jobbuilder; import Org. quartz. jobdetail; import Org. quartz. scheduler; import Org. quartz. schedulerexception; import Org. quartz. schedulerfactory; import Org. quartz. t Riggerbuilder; import Org. quartz. impl. stdschedulerfactory; import COM. jfinal. log. logger; import COM. jfinal. plugin. iplugin; public class quartzplugin implements iplugin {private final logger = logger. getlogger (getclass (); Private Static final string job = "job"; private string Config = "job. properties "; private properties; Public quartzplugin (string config) {This. config = config;} public Quartzplugin () {} private schedulerfactory; private scheduler; @ suppresswarnings ("unchecked") Public Boolean start () {try {loadproperties ();} catch (ioexception E) {logger. error (E. getmessage (); Return false;} If (properties = NULL) {return false;} schedulerfactory = new stdschedulerfactory (); try {scheduler = schedulerfactory. getscheduler ();} catch (schedulerexception e) {log Ger. error (E. getmessage (); Return false;} If (schedger = NULL) {logger. error ("scheduler is null"); Return false;} enumeration <Object> enums = properties. keys (); While (enums. hasmoreelements () {string key = enums. nextelement () + ""; if (! Key. endswith (job) |! Istrue (getjobkey (key, "enable") {continue;} string jobclassname = properties. get (key) + ""; string jobname = key. substring (0, key. lastindexof (". "); string jobcronexp = properties. getproperty (getjobkey (key, "cron") + ""; string jobgroup = properties. getproperty (getjobkey (key, "group", "jobgroup1"); Class <? Extends job> jobclass = NULL; try {jobclass = (class <? Extends job>) class. forname (jobclassname);} catch (classnotfoundexception e) {logger. error (E. getmessage (); Return false;} jobdetail job = jobbuilder. newjob (jobclass ). withidentity (jobname, jobgroup ). build (); crontrigger trigger = triggerbuilder. newtrigger (). withidentity ("Trigger", jobgroup ). withschedule (cronschedulebuilder. cronschedule (jobcronexp )). build (); try {scheduler. schedulejob (job, trigger); sch Edges. start ();} catch (schedulerexception e) {logger. error (E. getmessage (); Return false ;}} return true;} public Boolean stop () {try {scheduler. shutdown ();} catch (schedulerexception e) {logger. error (E. getmessage (); Return false;} return true;} private void loadproperties () throws ioexception {properties = new properties (); inputstream is = quartzplugin. class. getclassloader (). getresourceasstream (config ); Properties. load (is);} private string getjobkey (string STR, string type, string defaultvalue) {string key = getjobkey (STR, type ); if (Key = NULL | "". equals (key. trim () return defaultvalue; Return key;} private string getjobkey (string STR, string type) {return Str. substring (0, str. lastindexof (job) + type;} private Boolean istrue (string key) {object enable = properties. get (key); If (enable! = NULL & "false". inclusignorecase (enable + ""). Trim () {return false;} return true ;}}



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.