【发布时间】:2019-05-14 20:27:53
【问题描述】:
我有一个线程池,池大小的输入使用 spring 中的 @value 传递,其引用在 .properties 文件中。如下图:
@Value("${project.threadPoolSize}")
private static int threadPoolSize;
private static ScheduledExecutorService threadPool = Executors.newScheduledThreadPool(threadPoolSize);
@PostConstruct
public void MasterProcessService() {
try {
LOGGER.debug("Entering processServices in MasterProcessThread ");
当我尝试使用注释值给出线程池大小时,它只池化 1 个线程并执行睡眠操作,但稍后不会池化其他线程。
当我直接使用传递线程池大小时:
private static ScheduledExecutorService threadPool = Executors.newScheduledThreadPool(11);
它汇集所有线程并按照定义执行睡眠和运行状态。
谁能帮我在线程池大小中使用@Value 而不是直接定义一个数字?
【问题讨论】:
-
@Value不适用于static字段。
标签: java multithreading spring-boot threadpoolexecutor