You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@avalon.apache.org by Berin Loritsch <bl...@apache.org> on 2001/10/08 15:33:23 UTC

Re: cvs commit: jakarta-avalon/src/java/org/apache/avalon/framework/configuration Namespace.java DefaultConfigurationBuilder.java

Peter Donald wrote:
> 
> Hi,
> 
> Whats does everyone think of moving this Namespace cache into
> ConfigurationHandler and making it contain weak references? As it stands now
> the Namespace objects can never be reclaimed by GC.

Even better: don't cache them.

There was a similar discussion on Axis mailing list regarding QNames (it will
be an official class in the javax.xml.* packages).  Testing has found that
modern JVMs are very efficient at dealing with read only final classes like
Namespace and QName.  The overhead of cacheing was not only not worthwile,
sometimes it was a performance drain.

I wrote the caching mechanism before that email, and I am willing to remove
the caching impl.

> 
> On Wed, 3 Oct 2001 02:26, bloritsch@apache.org wrote:
> >   /**
> >    * The namespace object is used in configuration schemas where namespace
> > is * important.
> >    *
> >    * @author <a href="mailto:bloritsch@apache.org">Berin Loritsch</a>
> >    */
> >   public final class Namespace implements Serializable
> >   {
> >       private final static HashMap cache = new HashMap();
> >
> >       private final        String  m_prefix;
> >       private final        String  m_uri;
> >
> >       /**
> >        * Hide constructor so that the default factory methods must be used
> >        */
> >       private Namespace()
> >       {
> >           this("", "");
> >       }
> >
> >       /**
> >        * Create a Namespace object with a prefix and uri.
> >        */
> >       private Namespace( final String prefix, final String uri )
> >       {
> >           this.m_prefix = prefix;
> >           this.m_uri = uri;
> >       }
> ...snip...
> >
> >       /**
> >        * Get an instance of the Namespace with separate prefix and uri
> > strings *
> >        * @param  prefix  The prefix portion of the namespace
> >        * @param  uri     The uri portion of the namespace
> >        *
> >        * @return a Namespace object
> >        */
> >       public static final synchronized Namespace getNamespace( final String
> > prefix, final String uri ) {
> >           String pre = prefix;
> >           String loc = uri;
> >
> >           if ( null == prefix )
> >           {
> >               pre = "";
> >           }
> >
> >           if ( null == uri )
> >           {
> >               loc = "";
> >           }
> >
> >           Namespace ns = (Namespace) Namespace.cache.get( pre + loc );
> >
> >           if ( null == ns )
> >           {
> >              ns = new Namespace( pre, loc );
> >              Namespace.cache.put( pre + loc, ns );
> >           }
> >
> >           return ns;
> >       }
> >   }
> >
> 
> --
> Cheers,
> 
> Pete
> 
> ------------------------------------------------------
>  Mark Twain: "In the real world, the right thing never
> happens in the right place at the right time. It is
> the task of journalists and historians to rectify
> this error."
> ------------------------------------------------------
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: avalon-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: avalon-dev-help@jakarta.apache.org

---------------------------------------------------------------------
To unsubscribe, e-mail: avalon-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: avalon-dev-help@jakarta.apache.org