线程池配置【dry-parent】

package com.zskj.dry.config;

import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;

/**
 * 线程池配置
 *
 * @author 花开
 * @date 2017/11/29
 */
@Component
@ConfigurationProperties(prefix = "spring.task.executor")
public class TaskExecutorProperties {

    /** 线程池维护线程的最少数量 */
    private int corePoolSize;

    /** 线程池维护线程的最大数量 */
    private int maxPoolSize;

    /** 缓存队列 */
    private int queueCapacity;

    /** 允许的空闲时间 */
    private int keepAliveSeconds;

    public int getCorePoolSize() {
        return corePoolSize;
    }

    public void setCorePoolSize(int corePoolSize) {
        this.corePoolSize = corePoolSize;
    }

    public int getMaxPoolSize() {
        return maxPoolSize;
    }

    public void setMaxPoolSize(int maxPoolSize) {
        this.maxPoolSize = maxPoolSize;
    }

    public int getQueueCapacity() {
        return queueCapacity;
    }

    public void setQueueCapacity(int queueCapacity) {
        this.queueCapacity = queueCapacity;
    }

    public int getKeepAliveSeconds() {
        return keepAliveSeconds;
    }

    public void setKeepAliveSeconds(int keepAliveSeconds) {
        this.keepAliveSeconds = keepAliveSeconds;
    }
}

2,application-test.properties

spring.task.executor.core-pool-size=20
spring.task.executor.max-pool-size=30
spring.task.executor.queue-capacity=5
spring.task.executor.keep-alive-seconds=60

3

/**
 * 线程池
 *
 * @author 花开
 * @date 2017/11/29
 */
@Configuration
@EnableConfigurationProperties(TaskExecutorProperties.class)
public class TaskExecutorConfiguration {

    @Autowired
    private TaskExecutorProperties taskExecutorProperties;

    @Bean
    public ThreadPoolTaskExecutor taskExecutor() {
        ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
        executor.setCorePoolSize(taskExecutorProperties.getCorePoolSize());
        executor.setMaxPoolSize(taskExecutorProperties.getMaxPoolSize());
        executor.setQueueCapacity(taskExecutorProperties.getQueueCapacity());
        executor.setThreadNamePrefix("taskExecutor-");
        executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
        executor.setKeepAliveSeconds(taskExecutorProperties.getKeepAliveSeconds());
        executor.initialize();
        return executor;
    }
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
### 回答1: k8s的dry-run功能可以在不改变集群状态的情况下检查配置文件是否有语法错误或缺失。 要使用dry-run功能,需要在kubectl命令中添加--dry-run参数。例如,如果要在集群中创建一个新的pod,可以使用以下命令: ``` kubectl create --dry-run -f pod.yaml ``` 在这种情况下,将会检查pod.yaml文件中描述的pod是否合法,但不会在集群中创建该pod。 ### 回答2: Kubernetes的dry-run是一个非常有用的工具,可以用来在执行真正的操作之前进行预览和测试。通过使用dry-run,可以检查配置文件或命令的合法性和正确性,以避免潜在的问题和错误。 使用k8s的dry-run功能可以通过两种方式进行:使用kubectl命令行工具或在配置文件中添加dry-run标记。 使用kubectl命令行工具时,可以添加`--dry-run`参数来启用dry-run模式。例如,要创建一个名为`my-pod`的Pod对象,可以运行以下命令进行预览: ``` kubectl run my-pod --image=my-image --dry-run ``` 执行此命令后,将打印出生成的Pod对象的配置,而不会实际创建该对象。这样可以检查Pod对象的配置是否正确,并在实际执行操作之前进行必要的更改或修复。 另一种方法是在配置文件中添加dry-run标记。将`kind`字段设置为正确的资源类型,然后在文件的顶部或底部添加`--dry-run=client`行,如下所示: ``` apiVersion: v1 kind: Pod metadata: name: my-pod spec: containers: - name: my-container image: my-image ... --dry-run=client ``` 保存并退出配置文件后,可以使用kubectl命令运行以下命令来检查配置是否有效: ``` kubectl apply -f my-pod.yaml ``` 执行此命令后,kubectl将模拟应用配置文件,而不会真正创建Pod对象。如果存在任何问题或错误,将在输出中显示相应的错误消息,可以根据错误消息进行必要的修改。 总而言之,Kubernetes的dry-run非常有用,能够帮助我们在实际执行操作之前验证配置文件或命令的正确性,并及时发现潜在的问题和错误。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值