develog

Quartz cron expression test 본문

Dev/Java

Quartz cron expression test

냐옴 2012. 12. 4. 13:48

http://www.devexp.eu/2009/08/18/quartz-test-a-cron-expression/


CronExpressionTest.zip


public static void testCronExpression(String expression) {

    System.out.println(">> testCronExpression() : " + expression);

    try {

        CronExpression cronExpression = new CronExpression(expression);

        Date nextValidDate = new Date();

        for (int i = 0; i < 10; i++) {

            nextValidDate = cronExpression.getNextValidTimeAfter(nextValidDate);

            SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

            System.out.println("    " + formatter.format(nextValidDate));

        }

    } catch (ParseException e) {

        e.printStackTrace();

    }

}


public static void main(String[] args) {

    testCronExpression("* * * * * ?");

    testCronExpression("0/5 * * * * ?");

    testCronExpression("0 0 0 * * ?");

}


// console output

>> testCronExpression() : * * * * * ?

    2012-12-04 13:47:29

    2012-12-04 13:47:30

    2012-12-04 13:47:31

    2012-12-04 13:47:32

    2012-12-04 13:47:33

    2012-12-04 13:47:34

    2012-12-04 13:47:35

    2012-12-04 13:47:36

    2012-12-04 13:47:37

    2012-12-04 13:47:38

>> testCronExpression() : 0/5 * * * * ?

    2012-12-04 13:47:30

    2012-12-04 13:47:35

    2012-12-04 13:47:40

    2012-12-04 13:47:45

    2012-12-04 13:47:50

    2012-12-04 13:47:55

    2012-12-04 13:48:00

    2012-12-04 13:48:05

    2012-12-04 13:48:10

    2012-12-04 13:48:15

>> testCronExpression() : 0 0 0 * * ?

    2012-12-05 00:00:00

    2012-12-06 00:00:00

    2012-12-07 00:00:00

    2012-12-08 00:00:00

    2012-12-09 00:00:00

    2012-12-10 00:00:00

    2012-12-11 00:00:00

    2012-12-12 00:00:00

    2012-12-13 00:00:00

    2012-12-14 00:00:00

'Dev > Java' 카테고리의 다른 글

java get ip  (0) 2012.12.14
Apache Derby Eclipse plug-in  (0) 2012.12.08
Quartz Test  (0) 2012.12.04
ApplicationContext 가져오는 방법  (0) 2012.12.04
DTD-style vs Xml Schem-style in Spring 2.5  (0) 2012.12.04
Comments