linzhijie
2021-03-11 84fea994d2db7dc313ad1774f34eb12a45f8d6e7
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);
    }
}