package com.schisandra.auth.application.config;

import com.schisandra.auth.application.factory.CustomNameThreadFactory;
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;

/**
 * 线程池的config管理
 *
 * @author: landaiqing
 * @date: 2024/2/18
 */
@Configuration
public class ThreadPoolConfig {

    @Bean(name = "rotateCaptchaThreadPool")
    public ThreadPoolExecutor getLabelThreadPool() {
        return new ThreadPoolExecutor(20, 100, 5,
                TimeUnit.SECONDS, new LinkedBlockingDeque<>(40),
                new CustomNameThreadFactory("rotateCaptcha"),
                new ThreadPoolExecutor.CallerRunsPolicy());
    }
}
