简体   繁体   中英

Adjustable Threadpool and Queue

I am planning to create adjustable thread pool with adjustable queue size. I am using unbounded LinkedBlockingQueue with a external setting that controls how many messages are queued. Initially, my corepoolsize and maxpoolsize are equal. Now, if I want to update my threadpool size during runtime, I set corepoolsize and maxpoolsize through a common setting to a different value. I would like to know what do you think of this approach.

With maxpoolsize set to Integer.MAX_VALUE, can I just adjust corepoolsize as my queue is unbounded?

Is it a better idea to use SynchronousQueue with CallerRunsPolicy instead of LinkedBlockingQueue with external control?

IMPORTANT: I also want to know what happens when I decrease my corethreadpool size, will the tasks that are in progress gets abandoned in the middle?

I have few questions. What is the reason you are looking for SynchronousQueue? SynchronousQueue does not come with any capacity, even 1. According to documentation here - how to modify ThreadPoolTaskExecutor at runtime through jmx

A blocking queue in which each insert operation must wait for a corresponding remove operation by another thread, and vice versa. A synchronous queue does not have any internal capacity, not even a capacity of one.

So in my opinion, we should not be using it unless our usecase drive us to use the same. So I will not be able to make a comment unless we get a fair idea of your use-case.

About the threadpool, as you mentioned, CachedThreadPool does the exact functionality you require, except the core pool size, so you may want to evaluate the same. And reducing corepoolsize does not stop ongoing threads, unless the underlying task is over. So no need to worry about the same. how to modify ThreadPoolTaskExecutor at runtime through jmx

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM