梦幻之旅

DEBUG - 天道酬勤

   :: 首页 :: 新随笔 :: 联系 :: 聚合  :: 管理 ::
  671 随笔 :: 6 文章 :: 256 评论 :: 0 Trackbacks
package hvp.spring.quartz.simpleTrigger;

import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;

import org.quartz.JobDetail;
import org.quartz.Scheduler;
import org.quartz.SchedulerException;
import org.quartz.SchedulerFactory;
import org.quartz.SimpleTrigger;
import org.quartz.TriggerUtils;
import org.quartz.impl.StdSchedulerFactory;
import org.quartz.impl.calendar.AnnualCalendar;

public class CalendarExample
{
    
public void test() throws SchedulerException
    
{
        SchedulerFactory sf 
= new StdSchedulerFactory();
        Scheduler scheduler 
= sf.getScheduler();
        
        
// 法定节日以每年为周期
        AnnualCalendar holidays = new AnnualCalendar();
        
        Calendar laborDay 
= new GregorianCalendar();
        laborDay.add(Calendar.MONTH, 
5);
        laborDay.add(Calendar.DATE, 
1);
        
// 排除
        holidays.setDayExcluded(laborDay, true);
        
        Calendar nationalDay 
= new GregorianCalendar();
        nationalDay.add(Calendar.MONTH, 
10);
        nationalDay.add(Calendar.DATE, 
1);
        holidays.setDayExcluded(nationalDay, 
true);
        
        scheduler.addCalendar(
"holidays", holidays, falsefalse);
        
        Date runDate 
= TriggerUtils.getDateOf(001014);
        JobDetail job 
= new JobDetail("job""group1", SimpleJob.class);
        SimpleTrigger trigger 
= new SimpleTrigger("trigger1""group1",
                runDate, 
null, SimpleTrigger.REPEAT_INDEFINITELY,
                
60 * 60 * 1000);
        trigger.setCalendarName(
"holidays");
        scheduler.scheduleJob(job, trigger);
        scheduler.start();
    }

    
    
public static void main(String[] args) throws SchedulerException{
        CalendarExample ce 
= new CalendarExample();
        ce.test();
    }

}
posted on 2008-08-17 22:13 HUIKK 阅读(2542) 评论(0)  编辑  收藏

只有注册用户登录后才能发表评论。


网站导航: