package com.persagy.adm.diagram.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

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

/**
 * 自定义线程池
 *
 * @author liyang
 * @date 2021-12-31
 */
@Configuration
public class CustomThreadPoolConfig {

    /**
     * 发布自定义线程池
     *
     * @return 线程池
     */
    @Bean("customThreadPool")
    public ThreadPoolExecutor executor() {
        return new ThreadPoolExecutor(4, 10,
                2000, TimeUnit.MICROSECONDS,
                new LinkedBlockingDeque<>(20),
                r -> new Thread(r, "diagram_pool_" + r.hashCode()));
    }
}
