shikeying
2024-01-30 1a56cbb4cc61382d67be150acb2c3a91a679a808
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
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;
    }
}