Return-Path: Delivered-To: apmail-db-ojb-user-archive@www.apache.org Received: (qmail 71107 invoked from network); 9 Jun 2005 15:54:56 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 9 Jun 2005 15:54:56 -0000 Received: (qmail 99616 invoked by uid 500); 9 Jun 2005 15:54:53 -0000 Delivered-To: apmail-db-ojb-user-archive@db.apache.org Received: (qmail 99563 invoked by uid 500); 9 Jun 2005 15:54:52 -0000 Mailing-List: contact ojb-user-help@db.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Help: List-Post: List-Id: "OJB Users List" Reply-To: "OJB Users List" Delivered-To: mailing list ojb-user@db.apache.org Received: (qmail 99549 invoked by uid 99); 9 Jun 2005 15:54:52 -0000 X-ASF-Spam-Status: No, hits=0.0 required=10.0 tests= X-Spam-Check-By: apache.org Received-SPF: pass (hermes.apache.org: local policy) Received: from kika.risksys.ch (HELO kika.risksys.ch) (212.126.163.142) by apache.org (qpsmtpd/0.28) with ESMTP; Thu, 09 Jun 2005 08:54:52 -0700 Received: from localhost (kika [127.0.0.1]) by kika.risksys.ch (Postfix) with ESMTP id 39DCA1E2 for ; Thu, 9 Jun 2005 17:54:33 +0200 (CEST) Received: from kika.risksys.ch ([127.0.0.1]) by localhost (kika.risksys.ch [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 25615-09 for ; Thu, 9 Jun 2005 17:54:30 +0200 (CEST) Received: from [192.168.0.32] (darl.office.risksys.ch [192.168.0.32]) by kika.risksys.ch (Postfix) with ESMTP id ACD941BB for ; Thu, 9 Jun 2005 17:54:30 +0200 (CEST) Message-ID: <42A866D4.4030302@risksys.com> Date: Thu, 09 Jun 2005 17:57:08 +0200 From: Danilo Tommasina Organization: RCS AG User-Agent: Mozilla Thunderbird 1.0.2 (X11/20050517) X-Accept-Language: en-us, en MIME-Version: 1.0 To: OJB Users List Subject: Re: ThreadLocal causing memory leak References: <42A83DE5.4030503@risksys.com> <42A84D32.1030104@apache.org> In-Reply-To: <42A84D32.1030104@apache.org> X-Enigmail-Version: 0.90.2.0 X-Enigmail-Supports: pgp-inline, pgp-mime Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new-20030616-p10 (Debian) at risksys.com X-Virus-Checked: Checked X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N Hi again, and sorry for spamming the mailinglist :) Here is some code that can be applied to org.apache.ojb.broker.core.PersistenceBrokerThreadMapping to clean up the ThreadLocal stuff to be able to cleanly shutdown/reload a web-application without leaks in the PermGen. Using following code will no longer needs the workaround suggested in my previous mail. Add a new static field to the class: private static java.util.ArrayList loadedHMs = new java.util.ArrayList(); Modifiy the following method public static void setCurrentPersistenceBroker(PBKey key, PersistenceBroker broker) throws PBFactoryException { HashMap map = (HashMap) currentBrokerMap.get(); WeakHashMap set = null; if (map == null) { map = new HashMap(); currentBrokerMap.set(map); loadedHMs.add( map ); // ------------------ HERE IS IT } else { set = (WeakHashMap) map.get(key); } if (set == null) { // We emulate weak HashSet using WeakHashMap set = new WeakHashMap(); map.put(key, set); } set.put(broker, null); } Add this new method: /** Clean up static fields and any registered ThreadLocal contents to cleanly shutdown/reload OJB * within web-applications */ public static void shutdown() { for ( Iterator it = loadedWHM.iterator(); it.hasNext(); ) { ((HashMap) it.next()).clear(); } loadedHMs.clear(); loadedHMs = null; currentBrokerMap = null; } The PersistenceBrokerThreadMapping.shutdown() method must be called in your 'web application shutdown interceptor'. Since there are other routines in OJB that should be called when shutting down a web-application it would be nice to have a central method for doing this. Further routines that should be called are: // Release all persistence broker instances - PersistenceBrokerFactory.releaseAllInstances(); // Release all (pooled) db connections - ConnectionFactoryFactory.getInstance().createConnectionFactory().releaseAllResources(); - And stop any eviction Thread that is still running in background (see my first post) Please note that there are other ThreadLocal variables that are used in OJB depending on the config. Maybe it is also necessary to clean-up these variables (I did not test it) - MetadataManager.threadedRepository - MetadataManager.currentProfileKey - JTATxManager.txRepository Hopefully this can be of any help. bye danilo --------------------------------------------------------------------- To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org For additional commands, e-mail: ojb-user-help@db.apache.org