Quartz use the sample summary

2010-05-25  来源:本站原创  分类:Java  人气:191 

Task scheduling in the current JAVA applications use is widespread, it is necessary to master the skills QUARTZ

Gossip talk less, Shangguan Network: http://www.quartz-scheduler.org/ download the latest 1.80 Resource Kit

commons-logging log4j sff4j other packages to be added into the jar, quartz in the jar package is sure to be

First write a class that implements Job Interface

public class QuartzDemo implements Job{

        @Override
        public void execute(JobExecutionContext arg0) throws JobExecutionException {
                System.out.println("  Executive I  .......");

        }

}

Then write in a variety of test cases

public class Test {
    private static final SimpleTrigger CronTrigger = null;

        public static void main(String[] args){
    }

        public void test1(){
                  //  By SchedulerFactory to get a scheduler
        SchedulerFactory schedulerFactory = new StdSchedulerFactory();
        Scheduler scheduler;
                try {
                        scheduler = schedulerFactory.getScheduler();

        //  The introduction of operating procedures
        JobDetail jobDetail =
        new JobDetail("jobDetail-s1", "jobDetailGroup-s1", QuartzDemo.class);

         //new  A trigger
        SimpleTrigger simpleTrigger =
        new SimpleTrigger("simpleTrigger", "triggerGroup-s1");

        //  Set job start time  

        long ctime = System.currentTimeMillis();
        simpleTrigger.setStartTime(new Date(ctime));

        //  Set operation execution interval
        simpleTrigger.setRepeatInterval(1000);

        //  Set the number of job execution
        simpleTrigger.setRepeatCount(10);

        //  Set default job execution priority  5
        //simpleTrigger.setPriority(10);

        //  Operations and trigger settings to the scheduler in
        scheduler.scheduleJob(jobDetail, simpleTrigger);

        //  Start scheduler
        scheduler.start();
                } catch (SchedulerException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                }
        }

        public void test2(){

                try    {
            SchedulerFactory schedFact  =   new  org.quartz.impl.StdSchedulerFactory();
            Scheduler sched  =  schedFact.getScheduler();
            sched.start();
            JobDetail jobDetail  =   new  JobDetail( " Income Report " ,
                     " Report Generation " , QuartzDemo.class );
            jobDetail.getJobDataMap().put( " type " ,  " FULL " );
            CronTrigger trigger  =   new  CronTrigger( " Income Report " ,
                     " Report Generation " );
             /**/ /*    Once every 1 minute execution    */
            trigger.setCronExpression( "0 33 16 * * ?" );
            sched.scheduleJob(jobDetail, trigger);
        }   catch  (Exception e)   {
            e.printStackTrace();
        }
        }

        public void test3(){
                 //  By SchedulerFactory to get a scheduler
      SchedulerFactory schedulerFactory = new StdSchedulerFactory();
      Scheduler scheduler;
                try {
                        scheduler = schedulerFactory.getScheduler();
      //  The introduction of operating procedures
      JobDetail jobDetail =
      new JobDetail("jobDetail-s1", "jobDetailGroup-s1", QuartzDemo.class);
       //new  A trigger
      CronTrigger simpleTrigger =
        new CronTrigger("trigger", "group", "job", "group", "16 26/1 8-17 * * ?");
     // new SimpleTrigger("simpleTrigger", "triggerGroup-s1");

      //  Set job start time
        //Calendar excelCal = Calendar.getInstance();
                //excelCal.add(Calendar.DAY_OF_MONTH, 1);
                ///excelCal.set(Calendar.HOUR_OF_DAY, 16);
                //excelCal.set(Calendar.SECOND, 0);
                //excelCal.add(Calendar.MINUTE, 9);
     // long ctime = System.currentTimeMillis();
     // simpleTrigger.setStartTime(excelCal.getTime());
      //  Set operation execution interval
     // simpleTrigger.setRepeatInterval(1000);
      //  Set the number of job execution
     // simpleTrigger.setRepeatCount(10);
      //  Set default job execution priority  5
      //simpleTrigger.setPriority(10);

      //  Operations and trigger settings to the scheduler in
      scheduler.scheduleJob(jobDetail, simpleTrigger);

      //  Start scheduler
      scheduler.start();
                } catch (SchedulerException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                } catch (ParseException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                }

        }

}

Additional on-line after I collected

Quartz  Profile  :quartz.properties
# Configure Main Scheduler Properties
org.quartz.scheduler.instanceName = TestScheduler
org.quartz.scheduler.instanceId = one
# Configure ThreadPool
org.quartz.threadPool.class = org.quartz.simpl.SimpleThreadPool
org.quartz.threadPool.threadCount =  5
org.quartz.threadPool.threadPriority = 4
# Configure JobStore
org.quartz.jobStore.misfireThreshold = 5000
org.quartz.jobStore.class = org.quartz.simpl.RAMJobStore

  Attach  :cronExpression  Configuration instructions  

  Field allowed values       Special characters allowed
  Second      0-59    , - * /
  Point      0-59    , - * /
  Hour      0-23    , - * /
  Date      1-31    , - * ? / L W C
  1-12 months or   JAN-DEC    , - * /
  1-7 weeks or   SUN-SAT    , - * ? / L C #
  Years (  Optional  )      Blank  , 1970-2099    , - * / 

  Expression meaning
"0 0 12 * * ?"      Trigger every day at 12 noon
"0 15 10 ? * *"      Every morning  10:15  Trigger
"0 15 10 * * ?"      Every morning  10:15  Trigger
"0 15 10 * * ? *"      Every morning  10:15  Trigger
"0 15 10 * * ? 2005"    2005  Years, every morning  10:15  Trigger
"0 * 14 * * ?"      Day afternoon at 2 pm  2:59  Every 1 minute during the trigger
"0 0/5 14 * * ?"      Day afternoon at 2 pm  2:55  Triggered every 5 minutes during
"0 0/5 14,18 * * ?"      2 pm every day to  2:55  During and 6 pm to  6:55  Triggered every 5 minutes during
"0 0-5 14 * * ?"      Day afternoon at 2 pm  2:05  Every 1 minute during the trigger
"0 10,44 14 ? 3 WED"      Wednesday afternoon in March each year  2:10  And  2:44  Trigger
"0 15 10 ? * MON-FRI"      Weekday morning  10:15  Trigger
"0 15 10 15 * ?"      On the morning of 15th of each month  10:15  Trigger
"0 15 10 L * ?"      The morning of the last day of each month  10:15  Trigger
"0 15 10 ? * 6L"      Last Friday morning of each month  10:15  Trigger
"0 15 10 ? * 6L 2002-2005"    2002  Years to 2005 last Friday morning of each month  10:15  Trigger
"0 15 10 ? * 6#3"      The third Friday morning of each month  10:15  Trigger    

  Significance of special characters
*      That all values  :
?      Said the unspecified value, that is why the value does not care about it  :
-      That a specified range  :
,      That a possible value added  :
/      Sign in the indicated start time, symbol, said after the value of each incremental  :
L("last")    ("last") "L"   Used in day-of-month field means   "  The last day of the month  ":  Used in day-of-week field  ,   It simply means "7" or "SAT". If  day-of-week  Fields in and digital combined, it means that   "  This month's last day of the week "-     Such as  : "6L" means "  The last Friday of the month. "When we use  "L"  When a list does not specify the value or range is very important  ,  Otherwise, we will get some unexpected results  .
W("weekday")      Can only be used in day-of-month field  .  Depicts the closest to the specified working days  (  Monday to Friday  ).  Such as  :  In the day-of-month field use  "15W"  Means "closest to the first month  15  Day of days ", that is, if the first month  15  Day is Saturday, then the trigger will be the first in this month  14  Day of Friday to trigger  :  If the 15th day of the month is Sunday  ,  Then the trigger will be the 16th day of the month Mon trigger  :  If this is Tuesday the 15th day of month  ,  Then trigger the flip-flop on this day. Note that  : The use of only the calculated values in the current month, will not cross the current month  ."W"  Characters only in the day-of-month specified by day  ,  Can not be a range or list. You can also use the  "LW"  To specify the last working day of the month  .
#      Can only be used in day-of-week field  .  Used to specify the first few weeks of this month a few. Cases  :  In the day-of-week field use  "6#3"  Refers to the 3rd Friday this month  (6  That Friday, 3 means the  3  A  ).  If the specified date does not exist, the trigger will not trigger  .
C      After contacting means and the calendar had calculated the value of  .  Case  :  In the day-of-month field use  "5C"  Means this month or after the first 5 days, including  calendar  The first day  :  In the day-of-week field use  "1C"  In this Sunday on or after that, including the first day of calendar
相关文章
  • Quartz use the sample summary 2010-05-25

    Task scheduling in the current JAVA applications use is widespread, it is necessary to master the skills QUARTZ Gossip talk less, Shangguan Network: http://www.quartz-scheduler.org/ download the latest 1.80 Resource Kit commons-logging log4j sff4j ot

  • Quartz and its sample 2010-05-06

    Is the OpenSymphony Quartz Job scheduling open source organizations in the field of another open source project, it can be with J2EE and J2SE applications can also be used alone combined. Quartz can be used to create simple or as run 10, 100, or even

  • java call oracle stored procedure sample summary 2010-09-18

    oracle java stored procedure is called an example of a conclusion: no return value stored procedure Stored procedure is: create or replace procedure adddept (colno number, colname varchar2, colc varchar2) as begin insert into table values (colno, col

  • Flex4 the DataGrid additions and deletions to the data synchronization database and sample summary page 2010-11-05

    Indeed, on a lot of Flex's DataGrid article are fragmented, has not yet found an example of a complete reference for the users, this time I spent the next two days to do a Flex DataGrid indicators on the data management system, of course, mxml design

  • MySQL: MySQL date data sample. MySQL example, when the use of summary 2011-01-13

    MySQL Date Example: Date pattern, accounting for storage space, the date scale than force. Date of sample storage space the size of the date of the date pattern ------------ --------- --------------------- -------- --------------------------------- d

  • Quartz timer tasks framework for learning Summary 2010-11-01

    First details on the Quartz an article can refer to my blog, an article on the introduction of the framework. I did a web site of the project is an early warning system, through their own definition of an abstract class, the use of strategy pattern,

  • Fundamentals - Concept Summary (spring security.Quartz.JUnit test, etc.) 2010-11-04

    Interview may be useful 1, Spring Security framework and the general principles of (1) to configure the filter in the web.xml, so that you can control each request of this project. (2) in the applicationContext.xml configuration in which the http tab

  • Quartz set of time expressions 2010-03-29

    Quartz set of time expressions ----- corn Expression Time format: <! - Smhdmw (?) Y (?) ->, Respectively, correspond to: s "am" hours "on" on "weeks", the For example: 1. Every day when implemented: <value> 0 59 2

  • javascript under the arguments, caller, callee, call, apply the sample and understanding 2010-02-18

    Seeing everyone so concerned about the JS inside of these objects, I tried to text and then change it, and strive to give a detailed clarification of secondary significance. Referring to the above concepts, first like to talk about javascript functio

  • JS in the difference between IE and FireFox summary 2008-07-22

    JS in the difference between IE and FireFox summary 2009-06-04 11:31 by HeroBeast, 182 visits, net pick, collection, editing 1.event.srcElement 1: / / srcElement only target is to use IE to use FireFox, here is the compatibility written 2: var obj =

  • Commonly used summary of JSTL tags 2008-08-28

    JSTL core tag library include: expression operation, process control, iterative operations and URL action. The following are commonly used JSTL tag usage summary: 1, the expression operation 1. <c:out> Role: to display the data content. Syntax 1: Wi

  • JDK's URLConnection Summary 2008-07-29

    (Reproduced in: blog java: http://www.blogjava.net/xinwuhen/archive/2008/03/01/183159.html) For JDK's URLConnection connection Servlet question, on-line there though in relation to this, but it only shows one or several issues, based on the way to so

  • CAS (single sign) --- A Summary 2010-03-27

    Single sign-on (sso) is based on user / session authentication in a process, users simply provide a one-time certificate (only one log), you can access multiple applications. 1, the most recent system integration company, the company decided to use y

  • Quartz open-source framework for scheduling 2010-03-31

    Quartz open-source framework for scheduling Overview of various enterprise applications almost always run into scheduling needs, Take the Forum is: every half an hour the essence of the article generated RSS file, every morning and Statistics forum u

  • jQuery.FlexiGrid the use of summary 2010-03-30

    After a FlexiGrid of large-scale use, and refined from time to time under its code, to her understanding of a certain temperament, is the time to do the summary. 1, FlexiGrid downloads 1, original code Paulo P. Marinas right FlexiGrid recently made c

  • jQuery.FlexiGrid Use Summary 2010-03-30

    Through FlexiGrid are widely used, and refined from time to time under its code, a certain temperament to her understanding, is the time to take stock. 1, FlexiGrid download 1, original code Paulo P. Marinas on FlexiGrid recently made changes to adap

  • First-time Spring - quartz 2010-04-17

    Recently the company human resources needs, the daily newspaper as the company too, want to be a regular feature of automatic archiving report, in my guide with the help of the leadership of Kim, the basic function is achieved. Here is my summary of

  • Simple implementation of Spring Quartz Timer 2010-04-21

    1.spring.xml <!-- Timer requires code to be executed --> <bean></bean> <!-- The timer to execute --> <bean> <property name="triggers"> <list> <ref bean="jobTriggers" /> </list> <

  • Massive Data Processing Summary 2010-04-25

    I actually work in the honor of access to vast amounts of data processing issues, processes is an arduous and complicated task. Reasons to Under several aspects: 1, data overload, data and anything possible. If there are 10 data, then the big deal on

  • Transfer: How to run Android sdk sample of the unit test 2010-04-26

    Android 1.5_r1 the release notes specifically mentioned ADT0.9 JUnit support for improvement, for advocating TDD (Test Driven Development) of people this is good news today, take some time to talk about Android 1.5 in JUnit integration points related