On 04/05/2012 23:25, Gautam Bakshi wrote: > Thanks for the answer Miroslav. This brings up a few other questions to > me, mainly can I extend the life of a object in pool(these objects > shouldn't be dying if there is work)? Also, can I somehow specify a > minimum limit of objects so I can have them match the number of threads I > have(this way if the pool does get low the thread doesn't have to wait for > it to be created)?
Hmm. A couple of points. You are always going to see some blocking with a pooling implementation. What you see with 1.5/1.6 is less then you'll see with 1.4 an earlier. 2.x (currently a work in progress) will have even less blocking. If you each thread only uses one object at a time and you have a minimum pool size equal to the number of threads why bother with a pool? Just create an object when you create the thread and dedicate the object to the thread. Mark > > On Fri, May 4, 2012 at 5:41 PM, Miroslav Pokorny <miroslav.poko...@gmail.com >> wrote: > >> On Sat, May 5, 2012 at 12:07 AM, Gautam Bakshi <gautam.bak...@gmail.com >>> wrote: >> >>> Hi Everyone, >>> >>> I'm trying to pool some objects and share them but I noticed blocking in >>> the threads. I'm a bit new to Java so not sure if this is a problem with >> my >>> lack of experience or something specific to pools. Here's some code that >>> replicates the problem(Create 10 threads and share 20 objects, do this >> in a >>> long loop so you can catch the blocking). If you profile it(Java visualvm >>> or yourkit in the thread view), you'll notice that borrowObject seems to >> be >>> blocking the thread. So the question is, is this normal behavior or am I >>> doing something wrong? Is there any way I can get around it? >>> >>> Hi Gautum, >> >> What your describing is normal behaviour, after all if you ask the pool for >> an object and one is not available what else should it do. The best thing >> is to wait(block) until another thread returns a pooled item and then >> return with that. The reason for using pooling is typically the pooled >> objects are expensive or limited resources which is why your code does not >> simply create another one when it needs it, but rather waits its turn and >> then returns the pooled object when its used. >> >> hth >> >> mP >> > --------------------------------------------------------------------- To unsubscribe, e-mail: user-unsubscr...@commons.apache.org For additional commands, e-mail: user-h...@commons.apache.org