FreyaApplication.java 1.65 KB
package cn.fw.freya;

import cn.hutool.core.thread.ThreadFactoryBuilder;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.context.properties.ConfigurationPropertiesScan;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.context.annotation.Bean;
import org.springframework.data.jpa.repository.config.EnableJpaAuditing;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.transaction.annotation.EnableTransactionManagement;

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


/**
 * @author kurisu
 */
@EnableAsync
@EnableCaching
@SpringBootApplication
@EnableJpaAuditing
@EnableScheduling
@ConfigurationPropertiesScan
@EnableTransactionManagement
@EnableConfigurationProperties
public class FreyaApplication {
    public static void main(String[] args) {
        SpringApplication.run(FreyaApplication.class, args);
    }

    @Bean(value = "wmyThreadPool")
    public ThreadPoolExecutor getThreadPool() {
        return new ThreadPoolExecutor(
                6,
                6,
                30,
                TimeUnit.SECONDS,
                new LinkedBlockingQueue<>(1000),
                new ThreadFactoryBuilder().setNamePrefix("wmy-thread-pool-").build(),
                new ThreadPoolExecutor.DiscardPolicy());
    }
}