package com.ytpm.config;

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

import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ScheduledThreadPoolExecutor;
import java.util.concurrent.ThreadFactory;
import java.util.concurrent.ThreadPoolExecutor;

@Configuration
public class SchedulerConfig {

    @Bean(destroyMethod = "shutdown")
    public ScheduledExecutorService riskScheduledExecutorService() {
        ThreadFactory factory = r -> {
            Thread t = new Thread(r);
            t.setName("risk-scheduler");
            t.setDaemon(true);
            return t;
        };
        ScheduledThreadPoolExecutor executor = new ScheduledThreadPoolExecutor(5, factory, new ThreadPoolExecutor.DiscardPolicy());
        executor.setRemoveOnCancelPolicy(true);
        return executor;
    }
}


