[concurrency-interest] Unbounded thread pool and memory overhead

Peter Levart peter.levart at gmail.com
Mon Aug 25 07:31:21 EDT 2014


On 08/25/2014 11:11 AM, Rohit Reja wrote:
> I tried using this constructor
>
>   "new ThreadPoolExecutor(10, 100,
>                  60L, TimeUnit.SECONDS,
>>                  new LinkedBlockingQueue<Runnable>());"
> This results into creation of only 1 thread.
> According to the documentation, "If there are more than corePoolSize but less than maximumPoolSize threads running, a new thread will be created only if the queue is full."
>
> Essentially what I want is a cachedThreadPool with max threads < unbounded and queueing of tasks beyond a certain threshold.

You're right. Then you can set corePoolSize == maximumPoolSize < 
MAX_INTEGER and then invoke 
ThreadPoolExecutor.allowCoreThreadTimeOut(true). Also set 
'keepAliveTime' to some suitable value > 0.

Regards, Peter

>
>
> - Rohit
>
>
> On Monday, August 25, 2014 2:15 PM, "mail at sergey-mashkov.net" <mail at sergey-mashkov.net> wrote:
>   
>
>
> You can simply create instance of ThreadPoolExecutor using its constructor:
>
>
> http://docs.oracle.com/javase/7/docs/api/java/util/concurrent/ThreadPoolExecutor.html
>
> So You can specify bounds
>
>
> Kind regards
> Sergey Mashkov
>
> -----Original Message-----
> From: Rohit Reja <rreja2000 at yahoo.com>
> To: "concurrency-interest at cs.oswego.edu" <concurrency-interest at cs.oswego.edu>
> Sent: ??, 25 ???. 2014 9:37
> Subject: [concurrency-interest] Unbounded thread pool and memory overhead
>
>
> Hi,
>
> We are using Executors#newCachedThreadPool() at various places in our product. We recently faced an issue that the threads consumed lots of virtual memory in a machine ( and eventually the system has no memory left) due to lots of threads being created. ( We haven't set the Xss param though).
>
> I have 2 questions here:-
>
> 1. Why have this API choose not to have bounded threads ? What would be the best practices while using unbounded thread pools.
> 2. How can I build a thread pool with a minimum threads that grows to a max bound and then the task submission blocks?
>
> Thanks,
> Rohit
>
>
> On Thursday, August 14, 2014 6:03 PM, Victor Grazi <vgrazi at gmail.com> wrote:
>   
>
>
> There's a nice article by Dr. Heinz Kabutz on InfoQ http://www.infoq.com/articles/Hunting-Concurrency-Bugs-1
> Heinz always amazes me!
>
> Twitter: @vgrazi
> LinkedIn: www.linkedin.com/in/victorgrazi/
> Java Concurrent Animated: http://sourceforge.net/projects/javaconcurrenta/
> Skype: vgrazi2
>
> Google Plus
> _______________________________________________
> Concurrency-interest mailing list
> Concurrency-interest at cs.oswego.edu
> http://cs.oswego.edu/mailman/listinfo/concurrency-interest
>
>
> _______________________________________________
> Concurrency-interest mailing list
> Concurrency-interest at cs.oswego.edu
> http://cs.oswego.edu/mailman/listinfo/concurrency-interest

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://cs.oswego.edu/pipermail/concurrency-interest/attachments/20140825/452f7a19/attachment.html>


More information about the Concurrency-interest mailing list