Java Task Scheduler

Source: Internet
Author: User

The recent project to use the task scheduling related knowledge, yesterday confidence full to the official website to study, the result was pit a half-dead, I use the latest version of Quartz, the document is said to be compatible with all versions, but the code even compile all the error, helpless had to find information from the internet, Stones finally a little prospect, in this share, by the way Maven Project: Pom.xml references are as follows: org.quartz-scheduler quartz 2.1.7 org.quartz-scheduler quartz-oracle 2.1.7 org.quartz-scheduler quartz-weblogic 2.1.7 org.quartz-scheduler quartz-jboss 2.1.7 The relevant classes are as follows: Package Test.quartz;import Java.util.date;import Org.quartz.job;import org.quartz.jobexecutioncontext;import Org.quartz.jobexecutionexception;public class Simplejob implements job {//① Instance job interface method public void execute ( Jobexecutioncontext context) throws Jobexecutionexception {//Say Hello to the world and display the Date/time System.out . println ("Hello world! -"+ new Date ());}} Package Test.quartz;import Org.quartz.jobbuilder;import Org.quartz.jobdetail;import org.quartz.scheduler;import Org.quartz.schedulerfactory;import Org.quartz.simpleschedulebuilder;import Org.quartz.trigger;import Org.quartz.triggerbuilder;public class Simpletriggerrunner {public static void main (string[] args) throws Exception {Sch Edulerfactory schedfact = new Org.quartz.impl.StdSchedulerFactory (); Scheduler sched = Schedfact.getscheduler (); Define the job and tie it to our Hellojob class Jobdetail job = Jobbuilder.newjob (Simplejob.class). Withidentity ("MyJob" , "Group1"). Build (); Trigger the job to Run now, and then every seconds Trigger Trigger = Triggerbuilder.newtrigger (). Withidentity ("Mytrigger", "Group1"). Star Tnow (). Withschedule (Simpleschedulebuilder.simpleschedule (). Withintervalinseconds (2). RepeatForever ()). build (); Tell Quartz to schedule the job using our trigger sched.schedulejob (job, trigger); Sched.start (); Thread.Sleep (9L * 1000L); Sched.shutdown (TRUE); The demo above is the simplest example of getting started, and more complex instructions are required to refer to the documentation.

Java Task Scheduler

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.