Hello World of quartz

Source: Internet
Author: User
Tags time interval

The quartz framework is a scheduling framework in Java that can arbitrarily control the start time, end time, time interval, and time schedule of the task execution. While the quartz framework separates task jobs from trigger trigger, a job task can bind multiple trigger triggers at the same time, a loosely coupled state that allows the job to be reused easily.

Quartz framework design to the main classes are divided into three: Scheduler: The main scheduling class, responsible for task initialization, assignment, scheduling job: Represents a task class, which is the implementation of our final logic class Trigger: Triggers, representing the time point of task execution

Or, from the simplest HelloWorld, the use of the quartz framework

Define task Job First

public class Hellojob implements JOB {
            @Override public
            void execute (jobexecutioncontext jobexecutioncontext) Throws       jobexecutionexception {
                System.out.println ("Hello World");
            }
        

And then use Scheduler to dispatch the job.

Schedulerfactory factory = new Stdschedulerfactory ();
try {
    Scheduler Scheduler = Factory.getscheduler ();
    Scheduler.start ();

    Jobdetail Jobdetail = Jobbuilder.newjob (Hellojob.class). Withidentity ("Job1", "group1"). Build ();
    Trigger Trigger = Triggerbuilder.newtrigger ()
            . Withidentity ("Trigger1", "group1")
            . Withschedule ( Simpleschedulebuilder.simpleschedule (). RepeatForever (). Withintervalinseconds (). Build
();

      Scheduler.schedulejob (Jobdetail, trigger);
  } catch (Exception e) {
      e.printstacktrace ();
  }

This defines a timed task, and every 10s will perform a task of printing Hello World.

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.