// Path: src/main/java/com/baidu/unbiz/multitask/constants/DefaultThreadPoolConfig.java
// public class DefaultThreadPoolConfig implements ThreadPoolConfig {
// 
//     public int coreTaskNum() {
//         return CORE_TASK_NUM;
//     }
// 
//     public int maxTaskNum() {
//         return MAX_TASK_NUM;
//     }
// 
//     public int maxCacheTaskNum() {
//         return MAX_CACHE_TASK_NUM;
//     }
// 
//     public int queueFullSleepTime() {
//         return QUEUE_FULL_SLEEP_TIME;
//     }
// 
//     public long taskTimeoutMillSeconds() {
//         return TASK_TIMEOUT_MILL_SECONDS;
//     }
// }
// 
// Path: src/main/java/com/baidu/unbiz/multitask/constants/ThreadPoolConfig.java
// public interface ThreadPoolConfig extends TaskConfig {
// 
//     long taskTimeoutMillSeconds();
//     int queueFullSleepTime();
//     int maxCacheTaskNum();
//     int coreTaskNum();
//     int maxTaskNum();
// }


import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.Callable;
import java.util.concurrent.Executor;
import java.util.concurrent.Future;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.scheduling.concurrent.CustomizableThreadFactory;
import com.baidu.unbiz.multitask.constants.DefaultThreadPoolConfig;
import com.baidu.unbiz.multitask.constants.ThreadPoolConfig;
        Future<T> result = threadPool.submit(task);
        return result;
    }

    /**
     * 启动可并行Task,不关心结果
     *
     * @param task
     */
    public void invoke(Runnable task) {
        if (taskQueue.size() > 1) {
            LOG.debug("ReportTaskManager current taskQueue size is:" + taskQueue.size());
        }
        this.checkQueueFullThenSleep();
        threadPool.execute(task);
    }

    private void checkQueueFullThenSleep() {
        // 避免queue满后抛异常
        while (taskQueue.size() >= config.maxCacheTaskNum()) {
            LOG.info("TaskPoolManager thread pool blocking queue is full.");
            sleep(config.queueFullSleepTime());
        }
    }

    /**
     * 封装异常
     *
     * @param miliSeconds
     */
// Path: src/main/java/com/baidu/unbiz/multitask/constants/DefaultThreadPoolConfig.java
// public class DefaultThreadPoolConfig implements ThreadPoolConfig {
// 
//     public int coreTaskNum() {
//         return CORE_TASK_NUM;
//     }
// 
//     public int maxTaskNum() {
//         return MAX_TASK_NUM;
//     }
// 
//     public int maxCacheTaskNum() {
//         return MAX_CACHE_TASK_NUM;
//     }
// 
//     public int queueFullSleepTime() {
//         return QUEUE_FULL_SLEEP_TIME;
//     }
// 
//     public long taskTimeoutMillSeconds() {
//         return TASK_TIMEOUT_MILL_SECONDS;
//     }
// }
// 
// Path: src/main/java/com/baidu/unbiz/multitask/constants/ThreadPoolConfig.java
// public interface ThreadPoolConfig extends TaskConfig {
// 
//     long taskTimeoutMillSeconds();
//     int queueFullSleepTime();
//     int maxCacheTaskNum();
//     int coreTaskNum();
//     int maxTaskNum();
// }


// Path: src/main/java/com/baidu/unbiz/multitask/task/thread/TaskManager.java
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.Callable;
import java.util.concurrent.Executor;
import java.util.concurrent.Future;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.scheduling.concurrent.CustomizableThreadFactory;
import com.baidu.unbiz.multitask.constants.DefaultThreadPoolConfig;
import com.baidu.unbiz.multitask.constants.ThreadPoolConfig;

        Future<T> result = threadPool.submit(task);
        return result;
    }

    /**
     * 启动可并行Task,不关心结果
     *
     * @param task
     */
    public void invoke(Runnable task) {
        if (taskQueue.size() > 1) {
            LOG.debug("ReportTaskManager current taskQueue size is:" + taskQueue.size());
        }
        this.checkQueueFullThenSleep();
        threadPool.execute(task);
    }

    private void checkQueueFullThenSleep() {
        // 避免queue满后抛异常
        while (taskQueue.size() >= config.maxCacheTaskNum()) {
            LOG.info("TaskPoolManager thread pool blocking queue is full.");
            sleep(config.queueFullSleepTime());
        }
    }

    /**
     * 封装异常
     *
     * @param miliSeconds
     */
    public static final void sleep(int miliSeconds) {