All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.iiifi.kite.boot.configuration.KiteExecutorConfiguration Maven / Gradle / Ivy

There is a newer version: 1.2.4.RELEASE
Show newest version
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