commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Gautam Bakshi <>
Subject Re: [pool] Does borrowObject block?
Date Fri, 04 May 2012 22:25:19 GMT
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)?

On Fri, May 4, 2012 at 5:41 PM, Miroslav Pokorny <
> wrote:

> On Sat, May 5, 2012 at 12:07 AM, Gautam Bakshi <
> >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

  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message