0

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?

uday
  • 142
  • 2
  • 12
  • http://stackoverflow.com/questions/5719279/how-to-modify-threadpooltaskexecutor-at-runtime-through-jmx – Anand Vaidya Jan 25 '17 at 07:17
  • Why dont you try using CachedThreadPool? http://stackoverflow.com/questions/17957382/fixedthreadpool-vs-cachedthreadpool-the-lesser-of-two-evils – Anand Vaidya Jan 25 '17 at 07:21
  • CachedThreadPool will not help me as I want to increase/decrease threadpoolsize during runtime. – uday Jan 26 '17 at 01:14

1 Answers1

0

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

Community
  • 1
  • 1
Anand Vaidya
  • 1,374
  • 11
  • 26
  • SynchronousQueue with CallerRunsPolicy will essentially act as a queue, replacing the external control on the unbounded queue from the initial argument. – uday Jan 26 '17 at 01:01
  • Here, there is no complex processing on my tasks before queuing, so I don't really need to use a Queue to buffer tasks – uday Jan 26 '17 at 01:12