Quartz1.8.5 Example (ix)

Source: Internet
Author: User

/* Copyright 2005-2009 Terracotta, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); The * use of this file except-compliance with the License. Obtain a copy * of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * unless required by a Pplicable law or agreed into writing, software * Distributed under the License is distributed on a "as is" BASIS, Witho UT * Warranties or CONDITIONS of any KIND, either express or implied. See the * License for the specific language governing permissions and limitations * under the License. * */package Org.quartz.examples.example9;import Java.util.date;import Org.slf4j.logger;import Org.slf4j.loggerfactory;import Org.quartz.jobdetail;import Org.quartz.joblistener;import Org.quartz.Scheduler; Import Org.quartz.schedulerfactory;import Org.quartz.schedulermetadata;import Org.quartz.simpletrigger;import Org.quartz.examples.example2.simplejob;import org.quartz.impl.StdSchedulerFactory;/** * Demonstrates the behavior of <code>joblistener</code>s. In particular, * This example would use the a job listener to trigger another job after one * job succesfully executes. * */public class Listenerexample {public void run () throws Exception {Logger log = Loggerfactory.getlogger (Li        Stenerexample.class);        Log.info ("-------Initializing----------------------");        First we must get a reference to a scheduler schedulerfactory SF = new Stdschedulerfactory ();        Scheduler sched = Sf.getscheduler ();        Log.info ("-------Initialization complete-----------");        Log.info ("-------scheduling Jobs-------------------");        Schedule a job to run immediately jobdetail job = new Jobdetail ("Job1", "group1", Simplejob.class);                 Simpletrigger trigger = new Simpletrigger ("Trigger1", "group1", New Date (), NULL,        0, 0); Set up the Listener JoblIstener listener = new Job1listener ();        Sched.addjoblistener (listener);                        Make sure the listener are associated with the job Job.addjoblistener (Listener.getname ());                Schedule the job to run sched.schedulejob (job, trigger); All of the jobs had been added to the scheduler, but none of the jobs/would run until the scheduler has been        Started Log.info ("-------starting Scheduler----------------");        Sched.start ();        Wait seconds://note:nothing would run Log.info ("-------waiting seconds ...--------------");             try {//wait seconds to show jobs thread.sleep (30L * 1000L); Executing ...} catch (Exception e) {}//Shut down the Scheduler Log.info ('-------shutting down--        -------------------");        Sched.shutdown (TRUE); Log.info ("-------Shutdown complete-----------------");        Schedulermetadata metaData = Sched.getmetadata ();    Log.info ("Executed" + metadata.getnumberofjobsexecuted () + "jobs.");        public static void Main (string[] args) throws Exception {Listenerexample example = new Listenerexample ();    Example.run (); }}

  

/* Copyright 2005-2009 Terracotta, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); The * use of this file except-compliance with the License. Obtain a copy * of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * unless required by a Pplicable law or agreed into writing, software * Distributed under the License is distributed on a "as is" BASIS, Witho UT * Warranties or CONDITIONS of any KIND, either express or implied. See the * License for the specific language governing permissions and limitations * under the License. * */package Org.quartz.examples.example9;import Java.util.date;import Org.slf4j.logger;import Org.slf4j.loggerfactory;import Org.quartz.jobdetail;import Org.quartz.jobexecutioncontext;import Org.quartz.jobexecutionexception;import Org.quartz.joblistener;import Org.quartz.scheduler;import Org.quartz.schedulerexception;import org.quartz.simpletrigger;/** * @author wkratzer * * TODO to change the Template for the generated type comment go to * window-preferences-java-code Style-code Templates */public class        Job1listener implements Joblistener {private static Logger _log = Loggerfactory.getlogger (Job1listener.class);    Public String GetName () {return ' job1_to_job2 '; } public void jobtobeexecuted (Jobexecutioncontext incontext) {_log.info ("Job1listener says:job    executed. "); public void jobexecutionvetoed (Jobexecutioncontext incontext) {_log.info ("Job1listener says:job Execution is vet    OED. "); public void jobwasexecuted (Jobexecutioncontext incontext, jobexecutionexception inexception) {_log.info                ("Job1listener Says:job was executed.");                 Simple Job #2 jobdetail job2 = new Jobdetail ("Job2", Scheduler.default_group,                Simplejob2.class);  Simple trigger to fire immediately simpletrigger trigger =           New Simpletrigger ("Job2trigger", Scheduler.default_group, New Date (),                NULL, 0, 0L);            try {//Schedule the job to run!        Incontext.getscheduler (). Schedulejob (JOB2, Trigger);            } catch (Schedulerexception e) {_log.warn ("Unable to schedule job2!");        E.printstacktrace (); }            }}

/* Copyright 2005-2009 Terracotta, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); The * use of this file except-compliance with the License. Obtain a copy * of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * unless required by a Pplicable law or agreed into writing, software * Distributed under the License is distributed on a "as is" BASIS, Witho UT * Warranties or CONDITIONS of any KIND, either express or implied. See the * License for the specific language governing permissions and limitations * under the License. * */package Org.quartz.examples.example9;import Java.util.date;import Org.slf4j.logger;import Org.slf4j.loggerfactory;import Org.quartz.job;import Org.quartz.jobexecutioncontext;import  org.quartz.jobexecutionexception;/** * <p> * Just a simple job that gets fired off many times by example 1 * </p> * * @author Bill Kratzer */public class SimpleJob1 implements Job {PrivaTe static Logger _log = Loggerfactory.getlogger (Simplejob1.class);  /** * Empty constructor for Job Initilization */Public SimpleJob1 () {}/** * <p> * called By the <code>{@link org.quartz.scheduler}</code> when a * <code>{@link Org.quartz.trigger}</code     > fires that's associated with * the &LT;CODE&GT;JOB&LT;/CODE&GT;. * </p> * * @throws jobexecutionexception * If there is a exception while executing the job     . */public void execute (jobexecutioncontext context) throws Jobexecutionexception {//This job simply PRI NTS out its job name and the//date and time, it is running String jobName = Context.getjobdetail (). Get        FullName ();    _log.info ("SimpleJob1 says:" + jobName + "executing at" + New Date ()); }}

/* Copyright 2005-2009 Terracotta, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); The * use of this file except-compliance with the License. Obtain a copy * of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * unless required by a Pplicable law or agreed into writing, software * Distributed under the License is distributed on a "as is" BASIS, Witho UT * Warranties or CONDITIONS of any KIND, either express or implied. See the * License for the specific language governing permissions and limitations * under the License. * */package Org.quartz.examples.example9;import Java.util.date;import Org.slf4j.logger;import Org.slf4j.loggerfactory;import Org.quartz.job;import Org.quartz.jobexecutioncontext;import  org.quartz.jobexecutionexception;/** * <p> * Just a simple job that gets fired off many times by example 1 * </p> * * @author Bill Kratzer */public class SimpleJob2 implements Job {PrivaTe static Logger _log = Loggerfactory.getlogger (Simplejob2.class);  /** * Empty constructor for Job Initilization */Public SimpleJob2 () {}/** * <p> * called By the <code>{@link org.quartz.scheduler}</code> when a * <code>{@link Org.quartz.trigger}</code     > fires that's associated with * the &LT;CODE&GT;JOB&LT;/CODE&GT;. * </p> * * @throws jobexecutionexception * If there is a exception while executing the job     . */public void execute (jobexecutioncontext context) throws Jobexecutionexception {//This job simply PRI NTS out its job name and the//date and time, it is running String jobName = Context.getjobdetail (). Get        FullName ();    _log.info ("SimpleJob2 says:" + jobName + "executing at" + New Date ()); }}

[INFO] 22 months 03:56:06.271 PM main [org.quartz.examples.example9.ListenerExample]-------Initializing----------------- -----[INFO] 22 months 03:56:06.293 pm Main [org.quartz.simpl.simplethreadpool]job Execution threads would use class loader of T Hread:main[info] 22 months 03:56:06.307 PM Main [org.quartz.core.schedulersignalerimpl]initialized Scheduler Signaller of Ty Pe:class Org.quartz.core.schedulersignalerimpl[info] 22 months 03:56:06.308 PM main [Org.quartz.core.QuartzScheduler] Quartz Scheduler v.1.8.5 created. [INFO] 22 months 03:56:06.309 pm main [org.quartz.simpl.ramjobstore]ramjobstore initialized. [INFO] 22 months 03:56:06.310 PM Main [org.quartz.core.quartzscheduler]scheduler Meta-data:quartz Scheduler (v1.8.5) ' Defaul  Tquartzscheduler ' with InstanceId ' non_clustered ' Scheduler class: ' Org.quartz.core.QuartzScheduler '-running locally.  Not STARTED.  Currently in standby mode.  Number of jobs executed:0 Using thread pool ' org.quartz.simpl.SimpleThreadPool '-with ten threads. Using Job-store 'Org.quartz.simpl.RAMJobStore '-which does not the support persistence. and is not clustered. [INFO] 22 months 03:56:06.310 PM Main [Org.quartz.impl.stdschedulerfactory]quartz Scheduler ' Defaultquartzscheduler ' Initialized from the default resource file in Quartz package: ' Quartz.properties ' [INFO] 22 months 03:56:06.310 pm main [Org.quartz . Impl. Stdschedulerfactory]quartz Scheduler Version:1.8.5[info] 22 months 03:56:06.310 PM main [ Org.quartz.examples.example9.ListenerExample]-------Initialization complete-----------[INFO] 22 months 03:56:06.311 pm Main [org.quartz.examples.example9.ListenerExample]-------scheduling Jobs-------------------[INFO] 22 months 03:56:06.314 pm Main [org.quartz.examples.example9.ListenerExample]-------starting Scheduler----------------[INFO] 22 months 03:56:06.314 PM Main [Org.quartz.core.quartzscheduler]scheduler Defaultquartzscheduler_$_non_clustered started. [INFO] 22 months 03:56:06.314 PM main [org.quartz.examples.example9.ListenerExample]-------waiting-seconds ...---------- ----[DEbug] 22 months 03:56:06.316 PM Defaultquartzscheduler_quartzschedulerthread [org.quartz.simpl.SimpleJobFactory] Producing instance of Job ' Group1.job1 ', Class=org.quartz.examples.example2.simplejob[info] 22 months 03:56:06.319 pm defaultquartzscheduler_worker-1 [Org.quartz.examples.example9.job1listener]job1listener Says:job is about-be Executed. [DEBUG] 22 months 03:56:06.319 PM Defaultquartzscheduler_worker-1 [org.quartz.core.jobrunshell]calling execute on Job group1 . job1[info] 22 months 03:56:06.320 pm Defaultquartzscheduler_worker-1 [org.quartz.examples.example2.simplejob]simplejob Says:group1.job1 executing at Tue Feb 15:56:06 CST 2016[info] 22 months 03:56:06.320 pm Defaultquartzscheduler_worker-1 [o Rg.quartz.examples.example9.job1listener]job1listener Says:job was executed. [DEBUG] 22 months 03:56:06.321 PM Defaultquartzscheduler_quartzschedulerthread [org.quartz.simpl.SimpleJobFactory] Producing instance of Job ' Default.job2 ', Class=org.quartz.examples.example9.simplejob2[debug] 22 months 03:56:06.321 pm Defaultquartzscheduler_worker-2 [org.quartz.core.jobrunshell]calling execute on Job default.job2[info] 22 month 03:56 : 06.321 pm Defaultquartzscheduler_worker-2 [org.quartz.examples.example9.simplejob2]simplejob2 says:DEFAULT.job2 Executing at Tue 15:56:06 CST 2016[debug] 22 months 03:56:07.308 pm Timer-0 [org.quartz.utils.updatechecker]checking fo R available updated version of Quartz ... [INFO] 22 months 03:56:36.314 PM main [org.quartz.examples.example9.ListenerExample]-------shutting down----------------- ----[INFO] 22 months 03:56:36.314 PM main [Org.quartz.core.quartzscheduler]scheduler Defaultquartzscheduler_$_non_ CLUSTERED shutting down. [INFO] 22 months 03:56:36.314 PM main [Org.quartz.core.quartzscheduler]scheduler defaultquartzscheduler_$_non_clustered Paused. [DEBUG] 22 months 03:56:36.315 PM Main [Org.quartz.simpl.simplethreadpool]shutdown Complete[info] 22 months 03:56:36.315 PM main [ Org.quartz.core.quartzscheduler]scheduler defaultquartzscheduler_$_non_clustered shutdown complete. [INFO]22 months 03:56:36.315 PM main [org.quartz.examples.example9.ListenerExample]-------Shutdown complete-----------------[ INFO] 22 months 03:56:36.315 PM main [org.quartz.examples.example9.listenerexample]executed 2 jobs. [DEBUG] 22 months 03:56:36.495 pm DEFAULTQUARTZSCHEDULER_WORKER-10 [Org.quartz.simpl.simplethreadpool]workerthread is shut Down. [DEBUG] 22 months 03:56:36.495 pm Defaultquartzscheduler_worker-3 [Org.quartz.simpl.simplethreadpool]workerthread is shut Down. [DEBUG] 22 months 03:56:36.495 pm Defaultquartzscheduler_worker-8 [Org.quartz.simpl.simplethreadpool]workerthread is shut Down. [DEBUG] 22 months 03:56:36.495 pm Defaultquartzscheduler_worker-4 [Org.quartz.simpl.simplethreadpool]workerthread is shut Down. [DEBUG] 22 months 03:56:36.495 pm Defaultquartzscheduler_worker-5 [Org.quartz.simpl.simplethreadpool]workerthread is shut Down. [DEBUG] 22 months 03:56:36.495 pm Defaultquartzscheduler_worker-7 [Org.quartz.simpl.simplethreadpool]workerthread is shut Down. [DEBUG] 22 months 03:56:36.495 pm defaultquartzscheduler_worker-9 [Org.quartz.simpl.simplethreadpool]workerthread is shut down. [DEBUG] 22 months 03:56:36.495 pm Defaultquartzscheduler_worker-6 [Org.quartz.simpl.simplethreadpool]workerthread is shut Down. [DEBUG] 22 months 03:56:36.546 pm Defaultquartzscheduler_worker-2 [Org.quartz.simpl.simplethreadpool]workerthread is shut Down. [DEBUG] 22 months 03:56:36.546 pm Defaultquartzscheduler_worker-1 [Org.quartz.simpl.simplethreadpool]workerthread is shut Down.

  

Quartz1.8.5 Example (ix)

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.