Quartz scheduling framework for initial experience

Source: Internet
Author: User
Quartz is another open-source project of opensymphony open-source organization in the job scheduling field. It can be used together with J2EE and j2se applications. Quartz can be used to create complex daily program tables, such as ten, hundreds, and even tens of thousands of jobs. Jobs can be made into standard Java components or ejbs. The latest version of quartz is quartz 1.6.0.
         
            First, I created a Java project and exported a quartz. jar file to the class path.
            Create two classes as follows:
Testjob. Java

     Package csu.cn. test604;

Import java. util. date;

Import org. Quartz. jobdetail;
Import org. Quartz. scheduler;
Import org. Quartz. schedulerexception;
Import org. Quartz. schedulerfactory;
Import org. Quartz. simpletrigger;
Import org. Quartz. impl. stdschedulerfactory;
Import org. Apache. commons. Logging. logfactory;
Import javax. transaction. usertransaction;
Public class testjob {

 
 Public void test () throws schedulerexception {
  // Initiate a schedule Factory
  Schedulerfactory Sf = new stdschedulerfactory ();
  // Retrieve a scheduler from Schedule factory;
  Scheduler S = SF. getscheduler ();
  
  // Initiate jobdetail with job name, job group, and executable job class
  Jobdetail = new jobdetail ("autoinsepction", "inspection", xunhuan. Class );
  // Init simpletrigger
  Simpletrigger = new simpletrigger ("simpletrigger", null,
    New Date (), // start immediatly
    Null, simpletrigger. repeat_indefinitely, // repeat forever
    2L * 60l * 1000l
  ); // Every 2 minutes
  
  S. schedulejob (jobdetail, simpletrigger );
  // Start the Scheduler
  S. Start ();
  
 }
 Public static void main (string [] ARGs ){
  // Todo auto-generated method stub
      Testjob TJ = new testjob ();
      Try {
     TJ. Test ();
      }
      Catch (schedulerexception E)
      {
     E. printstacktrace ();
      }
 }

}
Execute xunhuan every two minutes

Package csu.cn. test604;

Import org. Quartz. job;
Import org. Quartz. jobexecutioncontext;
Import org. Quartz. jobexecutionexception;

Public class xunhuan implements job {

 Private Static int I = 0;
 @ Override
 Public void execute (jobexecutioncontext arg0) throws jobexecutionexception {
  // Todo auto-generated method stub
  System. Out. println ("no." + I + "");
  I ++;
 }

}

Because the first attempt was made, only one package was added. As a result, during the running, the old prompt XX was found every time.

So I tried to add the package again and again.
Log4j-1.2.15.jar

JTA. Jar                      Javax. Transaction

Commons-collections-3.2.jar  Org. Apache. commons. Collections

Commons-logging-api-1.1.jar  Org. Apache. commons. Logging
Finally, it runs successfully.
20:22:12 org. Quartz. simpl. simplethreadpool initialize
Information: job execution threads will use Class Loader of thread: Main
20:22:12 org. Quartz. Core. quartzscheduler <init>
Information: quartz scheduler v.1.6.0 created.
20:22:12 org. Quartz. simpl. ramjobstore initialize
Information: ramjobstore initialized.
20:22:12 org. Quartz. impl. stdschedulerfactory instantiate
Information: quartz scheduler 'ultultzscheduler 'initialized from default resource file in quartz package: 'z Z. properties'
20:22:12 org. Quartz. impl. stdschedulerfactory instantiate
Information: quartz schedversion version: 1.6.0
20:22:12 org. Quartz. Core. quartzscheduler start
Information: scheduler defaquartzscheduler _ $ _ non_clustered started.
0th calls
1st calls
......

 

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.