【问题标题】:Change value at Runtime in Spring Boot在 Spring Boot 的运行时更改值
【发布时间】:2021-09-17 16:17:50
【问题描述】:

我有以下代码。我可以在运行时更改 ThreadPoolExecutor 线程号大小吗? 我正在使用弹簧靴。

@Configuration
public class ExecutorConfig
{
 @Value(numberOfThreads)
 private String numberOfThreads ; // numberOfThreads is configured app.properties file
@Bean
 public ThreadPoolExecutor executorConfig()
 
 {
        ThreadPoolExecutor e =  Executors.newFixedThreadPool(numberOfThreads);
        
        return e;
}

}

【问题讨论】:

    标签: spring-boot spring-cloud-config


    【解决方案1】:

    一个选项是为属性 numberOfThread 添加一个 set 方法,然后提供一种更新它的方法,比如一个新的端点。但是如果您的应用重新启动,它仍然会从 application.properties 中获取之前的值。

    其他选项是使用Spring Cloud Config,但这对您的情况可能会也可能不会过大。

    此外,this answer 更深入地介绍了一些代码示例以强制重新加载。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-07-27
      • 2023-01-24
      • 2017-03-17
      • 1970-01-01
      • 2019-05-30
      • 1970-01-01
      • 2022-06-12
      相关资源
      最近更新 更多