On 4/29/15 12:55 PM, vijay wrote:
> Hi Phil..
>
> Thanks for response. i agree that add object is not problem as i am pre
> filling the pool and i can wait until the pool gets filled. But the real
> prob is with borrow object where i have to call the external system if
> there are no idle objects and the pool didn't reach the max size.
>
> In this case the pool will try to create new object by using factory make
> object method. The same method which add object also uses to add object to
> pool. I this case the borrow objeect call will get blocked until new
> connection is provided by external system (This could be some time more
> than 5 mins)
>
> The factory instance of the pool at this particular point has no
> information of whether the call has happened from borrow object or add
> object of pool to handle the time out based on add or borrow...This is
> where iam stuck ...
>
> can you help me how to implement it ..

Sorry, but pool can't really help with this use case.  The only
suggestion that I can make is to have your factory maintain state
itself - i.e., have it expose a property, say "timeLimited" and a
timeout value.  Have timeLimited false when you are preloading and
then set it to true and have the factory enforce the timeout. 
Another thing to note is that pool's borrowObject timeout limits the
amount of time that a thread waits for either an idle object or for
capacity to create one.  If a thread does get to create an object,
it will wait until the makeObject completes - i.e. (at least as of
2.3) the pool will not interrupt a thread waiting for a factory
method to complete.  That means that for your purpose, the
borrowObject timeout will not work either.

So basically the only solution that I can offer you is to have the
factory itself control the timeout.

Phil
>
> Thanks
>
> On Wed, Apr 29, 2015 at 2:19 PM, Phil Steitz <phil.ste...@gmail.com> wrote:
>
>> On 4/29/15 8:59 AM, vijay wrote:
>>> Hi ,
>>>
>>> I want to know if i can achieve this. Is there any way to specify time
>> out
>>> for the addobject and borrow object methods?
>>>
>>> What i am really looking is when i start the pool i am prefilling it with
>>> add object for this i can wait for more time to geth the pool
>> initialized.
>>> The backned system i have takes more time to crate connections
>>>
>>> But at the time of borrow i cannot have the client wait for long time if
>> no
>>> idle connection is available and the factory make object method might
>> take
>>> more time to  return object.
>>>
>>> So is there anyway i can tall factory method to wait for x time for add
>>> obkject and y time for borrow object calls
>> There is no timeout for addObject.  It is just a no-op if there is
>> no capacity to add to the pool when you call it.  If you are
>> prefilling at startup, that should not be a problem.  If you
>> actually *want* a timeout for the adds, then you need to implement
>> it in your factory itself.
>>
>> Phil
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscr...@commons.apache.org
>> For additional commands, e-mail: user-h...@commons.apache.org
>>
>>



---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscr...@commons.apache.org
For additional commands, e-mail: user-h...@commons.apache.org

Reply via email to