package com.kym.admin.config;

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

import java.util.concurrent.Executor;
import java.util.concurrent.Executors;


@Configuration
@EnableAsync  // 启用异步支持
public class AsyncConfig {

    /**
     * Java 21 虚拟线程异步执行器
     * 替代传统的ThreadPoolTaskExecutor，提供更好的并发性能
     */
    @Bean("AsyncExecutor")
    public Executor customAsyncExecutor() {
        // 使用虚拟线程池，每个任务都会获得一个轻量级的虚拟线程
        return Executors.newVirtualThreadPerTaskExecutor();
    }
}
