package com.walker.scheduler; import com.walker.infrastructure.utils.DateUtils; import com.walker.infrastructure.utils.WaitConsoleInput; import com.walker.scheduler.impl.ForeverScheduler; import org.junit.Test; public class TestScheduler { // @Test public void testEveryDayOnce(){ EveryDayScheduler scheduler = new EveryDayScheduler(1, "机构信息同步"); Option option = new Option(); // option.setPeriodType(Option.PeriodType.DAY); // option.setTimeType(Option.TimeType.EXACTLY); // int[] yearMonthDay = DateUtils.getCurrentYearMonthDay(); // // 设置每天凌晨3点执行 // int settingHour = 3; // option.setExactlyTime(yearMonthDay[0], yearMonthDay[1], yearMonthDay[2], settingHour); // scheduler.setOption(option); // scheduler.start(); // System.out.println("初始启动,option=" + scheduler.getOption()); option.setPeriodType(Option.PeriodType.MONTH); option.setTimeType(Option.TimeType.EXACTLY); int[] yearMonthDay = DateUtils.getCurrentYearMonthDay(); // 设置每天凌晨3点执行 int settingHour = 3; option.setExactlyTime(yearMonthDay[0], yearMonthDay[1], 19, settingHour); scheduler.setOption(option); scheduler.start(); System.out.println("初始启动,option=" + scheduler.getOption()); WaitConsoleInput.waitInput(); } // @Test public void testRunIdSchedulers(){ this.createIdScheduler(2, 5000).start(); this.createIdScheduler(5, 12000).start(); WaitConsoleInput.waitInput(); // 控制台输入:exit 退出 // scheduler.stop(); } private ForeverScheduler createIdScheduler(int id, long timeInterval){ IdForeverScheduler scheduler = new IdForeverScheduler(id, "任务"+id); scheduler.setTimeInterval(timeInterval); // 内核频率5秒 scheduler.setWaitSleepTime(60 * 1000); // 休眠1分钟 return scheduler; } }