liurunyu
2024-01-16 3028d5e6c90aa8768970bee0eeafea4a8228b2b6
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
package com.dy.common.mw.core;
 
import java.util.List;
 
import org.apache.logging.log4j.*;
 
public class CoreConstantManage {
    
    private final static Logger log = LogManager.getLogger(CoreConstantManage.class.getName()) ;
    
    private final static CoreConstantManage instance = new CoreConstantManage() ;
 
    private static Long sleepBigBusy = 100L ;//大忙时(除了恒久任务,还是其他任务),核心线程暂停间隔
    private static Long sleepSmallBusy = 500L ;//小忙时(只有恒久任务,无其他任务),核心线程暂停间隔
    
    private CoreConstantManage(){
    }
    
    public static CoreConstantManage getInstance(){
        return instance ;
    }
    
    /**
     * 设置暂停时长
     * @param sleepBigBusy 大忙时(除了恒久任务,还是其他任务),核心线程暂停间隔
     * @param sleepSmallBusy 小忙时(只有恒久任务,无其他任务),核心线程暂停间隔
     */
    public void setSleep(Long sleepBigBusy, Long sleepSmallBusy){
        CoreConstantManage.sleepBigBusy = sleepBigBusy ;
        CoreConstantManage.sleepSmallBusy = sleepSmallBusy ;
    }
 
    public void start(){
        //恒久任务
        List<CoreTask> constantTasks = CoreUnit.getAllConstantTasks();
        if (constantTasks != null && constantTasks.size() > 0) {
            for (CoreTask task : constantTasks) {
                new CoreConstantThread(sleepBigBusy, sleepSmallBusy, task).start();
            }
        }
    }
 
}