com.iiifi.kite.boot.configuration.KiteExecutorConfiguration Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of kite-boot Show documentation
Show all versions of kite-boot Show documentation
Spring Cloud Core Component Extension.
package com.iiifi.kite.boot.configuration;
import lombok.AllArgsConstructor;
import java.util.concurrent.Executor;
import java.util.concurrent.ThreadPoolExecutor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import com.iiifi.kite.boot.properties.KiteExecutorProperties;
import org.springframework.scheduling.annotation.AsyncConfigurerSupport;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.aop.interceptor.AsyncUncaughtExceptionHandler;
import org.springframework.aop.interceptor.SimpleAsyncUncaughtExceptionHandler;
/**
* @author [email protected] 花朝
* @date 2018/8/18 13:46
* @desc 异步配置
*/
@EnableAsync
@Configuration
@EnableScheduling
@AllArgsConstructor
@AutoConfigureAfter(KiteExecutorProperties.class)
public class KiteExecutorConfiguration extends AsyncConfigurerSupport {
private final KiteExecutorProperties kiteExecutorProperties;
@Bean
@Override
public Executor getAsyncExecutor() {
ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
executor.setCorePoolSize(kiteExecutorProperties.getCorePoolSize());
executor.setMaxPoolSize(kiteExecutorProperties.getMaxPoolSize());
executor.setQueueCapacity(kiteExecutorProperties.getQueueCapacity());
executor.setKeepAliveSeconds(kiteExecutorProperties.getKeepAliveSeconds());
executor.setThreadNamePrefix("kite-executor-");
executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
return executor;
}
@Override
public AsyncUncaughtExceptionHandler getAsyncUncaughtExceptionHandler() {
return new SimpleAsyncUncaughtExceptionHandler();
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy