Quartz (1)

Source: Internet
Author: User
  1. What is quartz?
    1. Quartz is an open-source job scheduling framework written in Java. It is quartz. net on the. NET platform. Quart can be used to quickly schedule tasks.
  2. What can quartz do/application scenarios?
    1. For example, in a webpage game, automatic cultivation is performed for 8 hours, and the number of characters is increased. When a certain item is used, the time is reduced to 4 hours, and the person gets the growth value. this involves the Scheduler operation.
    2. Online Games involve a large number of scheduler operations. If you are interested, you can think of scheduler.
  3. Comparison of similar frameworks
    1. Timetask is too simple and imperfect before quartz, and cannot directly meet developers' complicated application scenarios.
  4. Resources
    1. Official Website: http://www.quartz-scheduler.org/
    2. Download: http://www.quartz-scheduler.org/downloads
    3. Source SVN: http://svn.terracotta.org/svn/quartz
    4. This article uses Version 2.21:Download csdn or go to the official website.
    5. Demo:Sort and upload
  5. Framework Analysis
    1. Interface
    2. Class Diagram
  6. Design Mode in quartz
    1. Builder Mode
      1. All key components are built in the builder mode. <builder> For example: jobbuilder and triggerbuilder
    2. Factory Mode
      1. Finally, schedulerfactory combines various components such as schedulerfactory.
    3. The quartz project uses a large number of Component Modes, plug-in design, pluggable, low coupling, and easy scalability. developers can customize their own jobs, triggers, and other components.
  7. Core Framework Analysis
    1. Schedulerfactory -- scheduler Factory
      1. Stdschedulerfactory -- quartz default schedulerfactory
      2. Directschedulerfactory -- directschedulerfactory is a direct implementation of schedulerfactory, through which scheduler and threadpool can be directly built.
        1. Threadexecutor/defaultthreadexecutor -- Internal Thread operation object
    2. Jobexecutioncontext -- job context, stores information such as trigger and jobdeaitl. The parameters passed by the job execute method are the instance of the object.
      1. Jobexecutioncontextimpl
    3. Sched -- Scheduler
      1. Stdscheduler -- quartz default Scheduler
      2. Remotescheduler -- scheduler with RMI
    4. Job -- task object
      1. Jobdetail-it is a callback class for polling. It can encapsulate parameters into jobdatamap objects, and quartz stores the job status in jobdetail.
      2. Jobdatamap -- jobdatamap is used to report the task instance object passed by jobdetail.
    5. Trigger
      1. Simpletrigger <common trigger> -- simpleschedulebuilder
      2. Crontrigger <trigger with CRON like expression> -- cronschedulebuilder
      3. Calendarintervaltrigger <trigger triggered with date> -- calendarintervalschedulebuilder
      4. Dailytimeintervaltrigger <trigger triggered by day> -- dailytimeintervalschedulebuilder
    6. Threadpool -- provides some threads for quartz to run tasks.
      1. Simplethreadpool-a simple thread pool implemented by quartz by default. It is robust enough to deal with most common scenarios.
    7. ----- The above are some of the key objects involved in quartz. The detailed content will be available in subsequent articles!
  8. Quartz class diagram

    1. The class diagram consists of five parts: factory, bulider, schedder, trigger, and job.
  9. Thoughts
    1. // 1. Create a scheduler factory in the factory mode. STD is the default factory of quartz. developers can also implement their own factory, job, trigger, and other components.
      Schedulerfactory Sf = new stdschedulerfactory ();

      // 2. Get the scheduler object through schedulerfactory
      Scheduler sched = SF. getscheduler ();

      // Org. Quartz. datebuilder. evenminutedate -- built through datebuilder
      Date runtime = evenminutedate (new date ());

      // Org. Quartz. jobbuilder. newjob -- Build a job through jobbuilder
      Jobdetail job = newjob (hellojob. Class). withidentity ("job1", "group1"). Build ();

      // Build with triggerbuilder
      Trigger trigger = newtrigger (). withidentity ("trigger1", "group1"). startat (runtime). Build ();

      // Factory mode, assembling each component <job, trigger>
      Sched. schedulejob (job, trigger );

      Sched. Start ();
      Try {
      Thread. Sleep (65l * 1000l );
      } Catch (exception e ){
      }

      // Destroy the built-in trigger and job through schedgger
      Sched. Shutdown (true );
  10. Read quartz in one sentence
    1. 1. Create a scheduling Factory (); // factory Mode 2. Obtain the scheduler instance based on the factory (); // factory Mode 3. Build sub-components in builder mode <job, trigger> // builder mode, such as jobbuilder, triggerbuilder, and datebuilder 4. Assemble sub-component schedulers through schedulers. assemble <child component 1, child component 2...> // factory mode 5. scheduler. start (); // factory Mode
    2. ----- By weeks 2014-07-14 23:44:42

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.