zhuguifei
2026-03-10 2c1fd10c6fbabb8e9f0e9f07fe66fb36c008e883
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.shlanbao.tzsc.utils.tools;
 
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
/**
 * 线程管理
 * @author Leejean
 * @create 2015年1月7日下午1:20:18
 */
public class ThreadManager {
    
    private static ThreadManager threadManager = null;
    private ExecutorService executorService = Executors.newCachedThreadPool();
    private ScheduledExecutorService scheduledExecutorService = Executors.newScheduledThreadPool(10);
    
    private ThreadManager(){
        
    }
    
    public static ThreadManager getInstance(){
        if(threadManager == null){
            threadManager = new ThreadManager();
        }
        return threadManager;
    }
    
    /***
     * 新增执行线程
     * @param command
     */
    public void add(Runnable command){
        executorService.execute(command);
    }
    
    /***
     * 增加定时执行线程
     * @param command
     * @param initialDelay
     * @param delay
     * @param unit
     */
    public void addSchedule(Runnable command,int initialDelay,int delay,TimeUnit unit){
        scheduledExecutorService.scheduleWithFixedDelay(command, initialDelay, delay, unit);
    }
    
    public void shutDownThread() {
        scheduledExecutorService.shutdown();
    }
 
}