当前位置: 首页 > news >正文

spring boot通过文件配置yaml里面的属性

yaml文件

fsg:
batch-approval:# 批量审批batch-approval:pool:core-size: 2max-size: 10queue-capacity: 100keep-alive: 60name-prefix: ApprovalThread-shutdown:await-termination: trueawait-termination-period: 60

ConfigurationProperties配置


import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;import java.time.Duration;@Data
@ConfigurationProperties("fsg.batch-approval")
public class BatchApprovalProperties {private Pool pool = new Pool();private Shutdown shutdown = new Shutdown();@Datapublic static class Pool {/*** Queue capacity. An unbounded capacity does not increase the pool and therefore* ignores the "max-size" property.*/private int queueCapacity = 200;/*** Core number of threads.*/private int coreSize = 2;/*** Maximum allowed number of threads. If tasks are filling up the queue, the pool* can expand up to that size to accommodate the load. Ignored if the queue is* unbounded.*/private int maxSize = 10;/*** Whether core threads are allowed to time out. This enables dynamic growing and* shrinking of the pool.*/private boolean allowCoreThreadTimeout = true;/*** Time limit for which threads may remain idle before being terminated.*/private Integer keepAlive = 60;private String namePrefix = "ApprovalThread-";}@Datapublic static class Shutdown {/*** Whether the executor should wait for scheduled tasks to complete on shutdown.*/private boolean awaitTermination;/*** Maximum time the executor should wait for remaining tasks to complete.*/private Duration awaitTerminationPeriod;}}

使用配置文件的属性


import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;import java.util.concurrent.Executor;
@EnableAsync
@Configuration
@EnableConfigurationProperties(BatchApprovalProperties.class)
public class BatchApprovalAsyncConfig {@Bean(name = "batchApprovalTaskExecutor")public Executor batchApprovalTaskExecutor(BatchApprovalProperties props) {ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();executor.setCorePoolSize(props.getPool().getCoreSize()); // 核心线程数executor.setMaxPoolSize(props.getPool().getMaxSize()); // 最大线程数executor.setQueueCapacity(props.getPool().getQueueCapacity()); // 队列大小executor.setKeepAliveSeconds(props.getPool().getKeepAlive()); // 线程空闲时的存活时间executor.setThreadNamePrefix(props.getPool().getNamePrefix()); // 线程名称前缀executor.initialize(); // 初始化线程池return executor;}}

http://www.mrgr.cn/news/82212.html

相关文章:

  • vim交换文件的作用
  • 参数是模型学会的东西,预训练是让它学习的东西
  • Zbrush导入笔刷
  • 离线docker安装数据库(无法访问互联网),那么直接使用 docker pull mysql:latest
  • Linux 系统下查看磁盘是SSD还是HDD命令
  • 音频DSP的发展历史
  • Spring实现Logback日志模板设置动态参数
  • 19712 数字接龙
  • TTL 传输中过期问题定位
  • FOC控制原理7-源码解析2-系统滴答定时器中断
  • 使用ebooklib制作符合epub3规范的epub文件
  • C++语言编程————C++数据类型
  • 解决virtualbox克隆ubuntu虚拟机之后IP重复的问题
  • java Redisson 实现限流每秒/分钟/小时限制N个
  • 【复刻】ESG表现对企业价值的影响机制研究(2009-2021年)
  • 一、VxLAN 简介
  • 旷视科技Java面试题及参考答案
  • NRF24L01模块通信实验
  • 日期时间选择(设置禁用状态)
  • linux系统安装搭建chrony(ntp)时间同步服务器
  • git使用指南-实践-搭建git私服
  • 数据仓库中的指标体系模型介绍
  • Frontend - 分页(针对 python / Django )
  • 用Python操作字节流中的Excel工作簿
  • SpringCloud源码分析-Ribbon与LoadBalancer
  • python实现自动登录12306抢票 -- selenium