style: 优化部分 Properties 用法
This commit is contained in:
parent
5968f402ed
commit
48de2e85e0
@ -16,9 +16,8 @@
|
|||||||
|
|
||||||
package top.charles7c.cnadmin.common.config.properties;
|
package top.charles7c.cnadmin.common.config.properties;
|
||||||
|
|
||||||
import lombok.Data;
|
import lombok.AccessLevel;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
import org.springframework.stereotype.Component;
|
|
||||||
|
|
||||||
import cn.hutool.extra.spring.SpringUtil;
|
import cn.hutool.extra.spring.SpringUtil;
|
||||||
|
|
||||||
@ -29,8 +28,7 @@ import cn.hutool.extra.spring.SpringUtil;
|
|||||||
* @author Charles7c
|
* @author Charles7c
|
||||||
* @since 2022/12/21 20:21
|
* @since 2022/12/21 20:21
|
||||||
*/
|
*/
|
||||||
@Data
|
@NoArgsConstructor(access = AccessLevel.PRIVATE)
|
||||||
@Component
|
|
||||||
public class RsaProperties {
|
public class RsaProperties {
|
||||||
|
|
||||||
/** 私钥 */
|
/** 私钥 */
|
||||||
|
@ -20,11 +20,11 @@ import java.util.concurrent.ScheduledExecutorService;
|
|||||||
import java.util.concurrent.ScheduledThreadPoolExecutor;
|
import java.util.concurrent.ScheduledThreadPoolExecutor;
|
||||||
import java.util.concurrent.ThreadPoolExecutor;
|
import java.util.concurrent.ThreadPoolExecutor;
|
||||||
|
|
||||||
import lombok.RequiredArgsConstructor;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
|
||||||
import org.apache.commons.lang3.concurrent.BasicThreadFactory;
|
import org.apache.commons.lang3.concurrent.BasicThreadFactory;
|
||||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||||
|
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
|
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
|
||||||
@ -40,10 +40,9 @@ import top.charles7c.cnadmin.common.util.ExceptionUtils;
|
|||||||
*/
|
*/
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@Configuration
|
@Configuration
|
||||||
@RequiredArgsConstructor
|
@EnableConfigurationProperties(ThreadPoolProperties.class)
|
||||||
public class ThreadPoolConfiguration {
|
public class ThreadPoolConfiguration {
|
||||||
|
|
||||||
private final ThreadPoolProperties threadPoolProperties;
|
|
||||||
/** 核心(最小)线程数 = CPU 核心数 + 1 */
|
/** 核心(最小)线程数 = CPU 核心数 + 1 */
|
||||||
private final int corePoolSize = Runtime.getRuntime().availableProcessors() + 1;
|
private final int corePoolSize = Runtime.getRuntime().availableProcessors() + 1;
|
||||||
|
|
||||||
@ -52,7 +51,7 @@ public class ThreadPoolConfiguration {
|
|||||||
*/
|
*/
|
||||||
@Bean
|
@Bean
|
||||||
@ConditionalOnProperty(prefix = "thread-pool", name = "enabled", havingValue = "true")
|
@ConditionalOnProperty(prefix = "thread-pool", name = "enabled", havingValue = "true")
|
||||||
public ThreadPoolTaskExecutor threadPoolTaskExecutor() {
|
public ThreadPoolTaskExecutor threadPoolTaskExecutor(ThreadPoolProperties threadPoolProperties) {
|
||||||
ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
|
ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
|
||||||
// 核心(最小)线程数
|
// 核心(最小)线程数
|
||||||
executor.setCorePoolSize(corePoolSize);
|
executor.setCorePoolSize(corePoolSize);
|
||||||
|
@ -19,7 +19,6 @@ package top.charles7c.cnadmin.common.config.threadpool;
|
|||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
||||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||||
import org.springframework.stereotype.Component;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 线程池配置属性
|
* 线程池配置属性
|
||||||
@ -29,7 +28,6 @@ import org.springframework.stereotype.Component;
|
|||||||
* @since 2022/12/23 23:06
|
* @since 2022/12/23 23:06
|
||||||
*/
|
*/
|
||||||
@Data
|
@Data
|
||||||
@Component
|
|
||||||
@ConfigurationProperties(prefix = "thread-pool")
|
@ConfigurationProperties(prefix = "thread-pool")
|
||||||
public class ThreadPoolProperties {
|
public class ThreadPoolProperties {
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user