정시 실행 프로그램 - Quartz 간단한 실례

정시 실행 프로그램 - Quartz 간단한 실례
1、 가방 추가: Quartz 자체 quartz-1.8.3.jar와 의존 패키지commons-logging.jar  、slf4j-log4j12-1.5.10.jar 、slf4j-api-1.5.10.jar
2, 한 종류로 끝!!!,직접 실행
 import  org.quartz.CronTrigger;
 import  org.quartz.Job;
 import  org.quartz.JobDetail;
 import  org.quartz.JobExecutionContext;
 import  org.quartz.JobExecutionException;
 import  org.quartz.Scheduler;
 import  org.quartz.SchedulerFactory;
 import org.quartz.impl.StdSchedulerFactory;

 import  java.util.Date;

  public class QuartzReport implements  Job{

      public   void  execute(JobExecutionContext cntxt)  throws  JobExecutionException   {
        System.out.println( " :"+cntxt.getJobDetail().getJobDataMap().get("name")+new Date());
     }
 
      public static void  main(String[] args)   {
         try    {
            SchedulerFactory schedFact=new StdSchedulerFactory();
            Scheduler sched=schedFact.getScheduler();
            sched.start();
            JobDetail jobDetail=new JobDetail("a","b",QuartzReport.class);
            jobDetail.getJobDataMap().put("name","lucy");
           
            CronTrigger trigger=new  CronTrigger("c","d");
            trigger.setCronExpression("0/1 * * * * ? " ); //    。
            sched.scheduleJob(jobDetail, trigger);
           
        }   catch  (Exception e)   {
            e.printStackTrace();
        }
    }
} 

/*** 출력: *log4j: WARN No appenders could be found for logger(org.quartz.simpl.SimpleThreadPool).log4j:WARN Please initialize the log4j system properly. 출력: lucyWed Apr 13 15:11:54 CST 2011 출력: lucyWed Apr 13 15:11:56 CST 2011 출력: lucyWed Apr 13 15:11:57 CST 2011 출력: lucyWed Apr 13 15:11:58 CST 2011 출력: lucyWed Apr 13 15:11:59 CST 2011 출력: lucyWed Apr 13 15:12:00 CST 2011 출력: lucyWed Apr 13 15:01 12:02 CST 2011 출력: lucyWed Apr13 15:12:03 CST 2011 출력: lucyWed Apr 13 15:12:04 CST 2011 출력: lucyWed Apr 13 15:12:06 CST 2011 출력: lucyWed Apr 13 15:12:07 CST 2011 출력: lucyWed Apr 13 15:12:08 CST 2011 출력: lucyWed Apr 13 15:12: 09 CST 2011 출력: lucyWed Apr 13 15:12:10 CST 2011 출력: lucyWed Apr 13 15:12:10 11 CST 2011 출력: lucyWed Apr 13 15:12:12 CST 2011출력: lucyWed Apr 13 15:12:13 CST 2011 출력: lucyWed Apr 13 15:12:14 CST 2011
 */
첨부: cronExpression 구성 설명
 
 
 
 
 
초.
 
0-59
 
, - */
나누다
 
0-59
 
, - */
시간
 
0-23
 
, - */
날짜
 
1-31
 
, - * ?/L W C
월별
 
1-12 또는 JAN-DEC
 
, - */
요일
 
1-7 또는 썬-SAT.
 
, - * ?/L C#
년(옵션)
 
공백, 1970-2099
 
, - */

좋은 웹페이지 즐겨찾기