You are viewing a plain text version of this content. The canonical link for it is here.
Posted to ojb-user@db.apache.org by Danilo Tommasina <dt...@risksys.com> on 2005/08/02 12:10:44 UTC

Re: Cleaning up OJB when shutting down an application

Hi Armin,

sorry for the late answer, I just came back from holiday *sigh*.

I saw that you committed the patch and added the new shutdown() methods, great job. Thanks a lot.

Armin Waibel wrote:
> Hi Danilo,
> 
> Danilo Tommasina wrote:
> 
>> However calling the ObjectPool#close() from the realseAllInstaces() 
>> may be dangerous since after calling the ObjectPool#close() will no 
>> longer be usable and break future accesses to the PersistenceBroker.
> 
> 
> The pool instance itself will no longer be usable, but on a future
> access to the PB it force the ConnectionFactory implementation to create 
> a new ObjectPool.
> 

ok, this will also work...

> 
> I have a question related to your PersistenceBrokerThreadMapping-patch.
> Why is it not sufficient to nullify the ThreadLocal field only on
> shutdown (you trace all created maps using a HashSet)? Doesn't it free 
> the allocated memory?
> I ask this because OJB use ThreadLocal in other classes too (as 
> mentioned by Bob in MetadataManager). On shutdown I simply nullify these 
> fields.

Ok, I tested the stuff by just nullifing the field and it doesn't work, the leak is still there. I guess that the GC has some problem identifiing the object as 
trash. Probably because there are still links to active Threads within the ThreadLocal instance that should be garbage collected (I would call this a JVM and 
not an OJB issue, however we have to live with it)

It is not a problem if the HashMap that is put in the ThreadLocal variable is not nullified since the HashMap.class is always loaded by the bootstrap 
ClassLoader. Only the content of the HashMap is loaded by the web-app ClassLoader, clearing the content will remove any cross-link between ClassLoader contexts 
and solve the problem.
For the other classes using ThreadLocal, you may workaround the problem by always wrapping the objects added to ThreadLocal into an Map or a Collection and 
clearing the map/collection on shutdown. Do not use any custom class as wrapper since this will be loaded by the web-app ClassLoader, the wrapper must be a 
class loaded by the bootstrap class loader (the ones in the java.* package).

Is there already a timeframe for the release of OJB 1.0.4? We are going into beta stage with our app. in a couple of weeks and I have to decide if we have to:
- use the dirty work around in the PersistenceBrokerFactory or
- build from CVS or
- hope for a 1.0.4 release before we decide to freeze lib upgrades ;)

thanks again for everything
cheers
Danilo

---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-user-help@db.apache.org