[测评系统]--测评系统核心代码库
林致杰
2022-01-06 a72ce23de12389206780e726bd1700c40c7f6a82
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
package com.ots.framework.manager;
import com.ots.common.utils.Threads;
import com.ots.common.utils.spring.SpringUtils;
import java.util.TimerTask;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
 
public class AsyncManager {
    
    private final int OPERATE_DELAY_TIME = 10;
    
    private ScheduledExecutorService executor = SpringUtils.getBean("scheduledExecutorService");
    
    private AsyncManager() {
    }
    private static AsyncManager me = new AsyncManager();
    public static AsyncManager me() {
        return me;
    }
    
    public void execute(TimerTask task) {
        executor.schedule(task, OPERATE_DELAY_TIME, TimeUnit.MILLISECONDS);
    }
    
    public void shutdown() {
        Threads.shutdownAndAwaitTermination(executor);
    }
}