1. **
    2. * @function 自定义基础线程池
    3. * @author guo
    4. * @date 2022/6/27
    5. */
    6. public enum BasicExecuteThreadPool {
    7. /**
    8. * 22
    9. */
    10. INSTANCE;
    11. /**基础线程数量=cpu核数+1 */
    12. static int corePoolSize = Runtime.getRuntime().availableProcessors() + 1;
    13. /** 最大线程数量 = cpu 核树 * 4 */
    14. static int maxPoolSize = Runtime.getRuntime().availableProcessors() * 4;
    15. /** 超出核心线程的数量的线程!空闲存活时间 */
    16. static Long keepAliveTime = 0L;
    17. /** 默认队列大小 根据服务器性能而定 */
    18. private static final int DEFAULT_SIZE = 500;
    19. private static final BlockingQueue<Runnable> EXECUTE_QUEUE = new ArrayBlockingQueue<>(DEFAULT_SIZE);
    20. private static final ThreadPoolExecutor EXECUTOR = new ThreadPoolExecutor(
    21. corePoolSize,
    22. maxPoolSize,
    23. keepAliveTime,
    24. TimeUnit.MILLISECONDS,
    25. EXECUTE_QUEUE, new NameThreadFactory("Exchange_Conn"));
    26. BasicExecuteThreadPool() {}
    27. public void submitTask(Runnable runnable) {
    28. EXECUTOR.execute(runnable);
    29. }
    30. }