-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Question] Provide boolean parameter to support prestartCoreThread or prestartAllCoreThreads #1100
Labels
Comments
在替换动态线程池前,会有任务执行么? |
@magestacks 更新了一下之前的描述,详细描述了下场景 |
@magestacks 复现步骤:
spring:
dynamic:
thread-pool:
banner: false
notify-platforms:
executors:
- thread-pool-id: 'xxx'
core-pool-size: 5
maximum-pool-size: 5
blocking-queue: 'LinkedBlockingQueue'
queue-capacity: 10
keep-alive-time: 60
allow-core-thread-time-out: false
@SpringBootApplication
@EnableDynamicThreadPool
public class DemoApplication {
@Bean
@DynamicThreadPool
public ThreadPoolExecutor testThreadPoolExecutor() {
ThreadPoolExecutor tpe = ThreadPoolBuilder.builder()
.corePoolSize(5)
.maxPoolNum(5)
.threadFactory("xxx")
.threadPoolId("xxx")
.dynamicPool()
.build();
tpe.prestartAllCoreThreads();
return tpe;
}
public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
}
}
@Slf4j
@RestController
@RequestMapping("/")
public class TestController {
@Autowired
private ThreadPoolExecutor testThreadPoolExecutor;
@GetMapping("test")
public void test() {
for (int i = 0; i < 20; i++) {
testThreadPoolExecutor.execute(() -> System.out.println("ignore"));
BlockingQueue<Runnable> queue = testThreadPoolExecutor.getQueue();
log.info("queue.size(): " + queue.size());
log.info("queue.remainingCapacity(): " + queue.remainingCapacity());
}
}
}
该线程池中的 5 条线程将永远阻塞在 queue 6354 等待获取任务,但其实所有任务进 queue 6385 却无线程去执行 queue 6385 中的任务,导致后续队列满出现拒绝策略 |
是的。建议线程池的queue不要直接替换,而应该使用代理的方式,将原始的queue取出完成代理后使用反射(<jdk8)或unsafe(>=jdk8)替换原始的queue引用就可以了。 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
需求建议
请在提交问题之前回答这些问题,谢谢。
您的功能请求是否与问题有关?
是
描述你想要的功能
ExecutorProperties 提供 boolean 参数支持 prestartCoreThread or prestartAllCoreThreads
server 模式可提供相关按钮和接口来支持 prestartCoreThread or prestartAllCoreThreads
支持该功能的必要性
目前如果用户有此需求,会通过手动调用 prestartCoreThread or prestartAllCoreThreads。假设以下场景:config 模式下
配置文件中指定:
build() 时 tpe 中阻塞队列会设置默认 queue(称为 queue1),调用 prestartAllCoreThreads 后,10 条核心线程阻塞在 queue1 中等待获取任务
后续通过配置将 tpe 中阻塞队列设置为新的 queue(称为 queue2)
The text was updated successfully, but these errors were encountered: