首页 > 编程语言 >Java基于枚举类的线程池

Java基于枚举类的线程池

时间:2023-02-04 16:13:12浏览次数:50  
标签:java 枚举 线程 import Java MedDetailThreadPool pool ThreadPoolExecutor

  1. 线程池定义(可防序列化攻击)
package com.yang.utils;

import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * @author yangjx
 * @date 2021/8/26 10:56
 * @description
 */
public enum MedDetailThreadPool {

    /**
     * 日志记录
     */
    LOG_POOL(new ThreadPoolExecutor(
            16,
            32,
            30,
            TimeUnit.MINUTES,
            new ArrayBlockingQueue<Runnable>(2048),
            new ThreadPoolExecutor.CallerRunsPolicy()
    ));

    /**
     * 线程池
     */
    private final ThreadPoolExecutor pool;

    MedDetailThreadPool(ThreadPoolExecutor pool) {
        this.pool = pool;
    }

    public ThreadPoolExecutor getPool() {
        return pool;
    }
}
  1. 使用线程池
  MedDetailThreadPool.LOG_POOL.getPool().execute(() -> System.out.println());

标签:java,枚举,线程,import,Java,MedDetailThreadPool,pool,ThreadPoolExecutor
From: https://www.cnblogs.com/JaxYoun/p/17091739.html

相关文章