I am using LinkedBlockingQueue as workqueue in ThreadPoolExecutor. Problem is shall i use bounded LinkedBlockingQueue or unbounded LinkedBlockingQueue. I have overridden execute method of ThreadPoolExecutor and no longer facing the problem of thread creation after core pool size.
So please tell me which will be better one to use LinkedBlockingQueue bounded or unbounded.
Thanks, Tushar
Unbounded queue is secure way to ensure no task is rejected, or use bounded queue with such a capacity that is so large that it is capable of holding maximum number of tasks that can come in your application. That depends on design of your application. I think if you understand(discuss with architect) application design, you would be able to decide upon size of queue. And about memory and CPU, unless you add tasks to the queue, they wont increase, and will be same for both - unbounded or bounded. (Tested in demo application)
public static void main(String[] args)
{
LinkedBlockingQueue<Runnable> r = new LinkedBlockingQueue<Runnable>(11);
while(true)
{
// r.offer(new Task(1));
}
}
just play around with size to check.