<!--元数据处理器-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
</dependency>
package com.kun.product.config;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import java.util.concurrent.Executors;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
@Configuration
public class MyThredConfig {
@Bean
public ThreadPoolExecutor threadPoolExecutor(ThredPoolConfigProperties thread)
{
return new ThreadPoolExecutor(thread.getCoreSize(),
thread.getMaxSize(),
thread.getKeepAliveTime(),
TimeUnit.SECONDS,
new LinkedBlockingQueue<>(100000),
Executors.defaultThreadFactory(),
new ThreadPoolExecutor.AbortPolicy()
);
}
}
package com.kun.product.config;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;
@ConfigurationProperties(prefix = "thread")
@Component
@Data
public class ThredPoolConfigProperties {
private Integer CoreSize;
private Integer MaxSize;
private Integer KeepAliveTime;
}
thread:
core-size: 20
keep-alive-time: 10
max-size: 200