package com.zanxiang.game.back.serve.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.AsyncConfigurer;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;

import java.util.concurrent.Executor;

/**
 * @author : lingfeng
 * @time : 2024-05-27
 * @description : 异步配置
 */
@Configuration
@EnableAsync
public class AsyncConfig implements AsyncConfigurer {

    @Override
    public Executor getAsyncExecutor() {
        ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
        //设置核心线程数
        executor.setCorePoolSize(15);
        //设置最大线程数
        executor.setMaxPoolSize(30);
        //设置队列容量
        executor.setQueueCapacity(20);
        executor.initialize();
        return executor;
    }
}
