commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Slawek Zachcial <slawek_zachc...@yahoo.com>
Subject Re: ObjectPool - weak reference based impl
Date Mon, 28 Jan 2002 23:20:59 GMT
Hi,

Can someone have a look at the attached
SoftRefObjectPool and TestSoftRefObjectPool classes.
If I have your "go" I'll add comments and create
factory class and "keyed" versions.

Both were very much inspired by their
GenericObjectPool counterparts. 

SoftRefObjectPool has a CursorableLinkedList on which
it stores ObjectHolder (inner class) instances -
ObjectHolder is used to call _factory.destroyObject in
its finalize method. There is no Evictor thread as the
job is done by Garbage Collector

The test class has most methods from
TestGenericObjectPool - non-regression. In addition it
has testOutOfMemory. The idea is to make sure that
before this error is thrown the idle objects are
cleared.

Finally, I think that in
GenericObjectPool.returnObject the condition (_maxIdle
> 0 && (_pool.size() >= _maxIdle || (_testOnReturn &&
!_factory.validateObject(obj))))
should be rather something like
( (_maxIdle > 0 && _pool.size() >= _maxIdle) |
  (_testOnReturn && !_factory.validateObject(obj)) )
I know it's wired but for _maxIdle==0 and
_testOnReturn==true in the condition above
_factory.validateObject would never get called.

Give me your comments and I'll complete the SoftRef
classes.

Best Regards,
Slawek

--- crazybob@crazybob.org wrote:
> Actually, it's good to use a SoftReference-based
> pool in production, and a WeakReference-based pool
> in development and debugging. It makes it a lot
> easier to test what will happen when instances start
> getting collected.
> 
> Bob
> 
> On Fri, Jan 25, 2002 at 07:53:15AM -0600, Waldhoff,
> Rodney wrote:
> > That should probably be SoftReference--so that the
> pooled object may be
> > gc'ed if memory is tight.
> > 
> > -----Original Message-----
> > From: Slawek Zachcial
> > To: commons-dev@jakarta.apache.org
> > Sent: 1/25/02 3:16 AM
> > Subject: ObjectPool - weak reference based impl
> > 
> > Hi,
> > 
> > I noticed that on the pool todo list there is the
> > action to implement weak reference based pool.
> > 
> > Can someone explain to me what is the reason/need
> > behind? Should the idle pool objects be stored
> with
> > weak references?
> > 
> > My understanding is that you use object pool to
> avoid
> > the unnecessary object creation and rather reuse
> the
> > existing ones.
> > 
> > With weak references the object may/will be
> cleared
> > once it becomes weakly reachable. So if idle pool
> > objects are weakly reachable you cannot be sure
> that
> > they will not be garbage collected.
> > 
> > I'm not a reference specialist so please help me
> to
> > understand :-)
> > 
> > Best Regards,
> > Slawek Zachcial
> > 
> > __________________________________________________
> > Do You Yahoo!?
> > Great stuff seeking new owners in Yahoo! Auctions!
> 
> > http://auctions.yahoo.com
> > 
> > --
> > To unsubscribe, e-mail:
> >
> <mailto:commons-dev-unsubscribe@jakarta.apache.org>
> > For additional commands, e-mail:
> > <mailto:commons-dev-help@jakarta.apache.org>
> 
> --
> To unsubscribe, e-mail:  
> <mailto:commons-dev-unsubscribe@jakarta.apache.org>
> For additional commands, e-mail:
> <mailto:commons-dev-help@jakarta.apache.org>
> 


=====
Best Regards,
Slawek

__________________________________________________
Do You Yahoo!?
Great stuff seeking new owners in Yahoo! Auctions! 
http://auctions.yahoo.com
Mime
View raw message