You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@turbine.apache.org by he...@apache.org on 2004/08/24 23:11:52 UTC

cvs commit: jakarta-turbine-2/src/java/org/apache/turbine/services/assemblerbroker/util/java JavaBaseFactory.java

henning     2004/08/24 14:11:52

  Modified:    .        Tag: TURBINE_2_3_BRANCH project.xml
               xdocs    Tag: TURBINE_2_3_BRANCH changes.xml
               src/java/org/apache/turbine/services/assemblerbroker/util/java
                        Tag: TURBINE_2_3_BRANCH JavaBaseFactory.java
  Log:
  Add a Class Cache for the Java Assemblerbroker factories to speed up
  the name to class translation process.
  
  Patch supplied by Brian Lawler (brian@tribenetwork.com).
  
  Revision  Changes    Path
  No                   revision
  No                   revision
  1.136.2.12 +5 -1      jakarta-turbine-2/project.xml
  
  Index: project.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-turbine-2/project.xml,v
  retrieving revision 1.136.2.11
  retrieving revision 1.136.2.12
  diff -u -r1.136.2.11 -r1.136.2.12
  --- project.xml	22 Aug 2004 23:51:59 -0000	1.136.2.11
  +++ project.xml	24 Aug 2004 21:11:51 -0000	1.136.2.12
  @@ -22,7 +22,7 @@
     <pomVersion>3</pomVersion>
     <name>jakarta-turbine-2</name>
     <id>turbine</id>
  -  <currentVersion>2.3.1-rc2</currentVersion>
  +  <currentVersion>2.3.1-rc3-dev</currentVersion>
     <organization>
       <name>Apache Software Foundation</name>
       <url>http://jakarta.apache.org/</url>
  @@ -245,6 +245,10 @@
       <contributor>
         <name>Chris Kimpton</name>
         <email>kimptoc.mail@bigfoot.com</email>
  +    </contributor>
  +    <contributor>
  +      <name>Brian Lawler</name>
  +      <email>brian@tribenetwork.com</email>
       </contributor>
       <contributor>
         <name>Josh Lucas</name>
  
  
  
  No                   revision
  No                   revision
  1.60.2.20 +17 -0     jakarta-turbine-2/xdocs/changes.xml
  
  Index: changes.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-turbine-2/xdocs/changes.xml,v
  retrieving revision 1.60.2.19
  retrieving revision 1.60.2.20
  diff -u -r1.60.2.19 -r1.60.2.20
  --- changes.xml	22 Aug 2004 23:52:00 -0000	1.60.2.19
  +++ changes.xml	24 Aug 2004 21:11:52 -0000	1.60.2.20
  @@ -73,6 +73,23 @@
   -->
   
   
  +<section name="Turbine 2.3-rc3-dev">
  +
  +<subsection name="Other changes">
  +<p>
  +  <ul>
  +    <li>
  +       JavaBaseFactory executed a Class.forName() every time it was
  +       searching for a named class, which showed up as a very costly
  +       API call in our profiling.  A synchronized cache has been added
  +       to cache previously obtained class instances inside this class.
  +    </li>
  +  </ul>
  +</p>
  +</subsection>
  +
  +</section>
  +
   <section name="Turbine 2.3-rc2">
   
   <p>
  
  
  
  No                   revision
  No                   revision
  1.8.2.4   +16 -2     jakarta-turbine-2/src/java/org/apache/turbine/services/assemblerbroker/util/java/JavaBaseFactory.java
  
  Index: JavaBaseFactory.java
  ===================================================================
  RCS file: /home/cvs/jakarta-turbine-2/src/java/org/apache/turbine/services/assemblerbroker/util/java/JavaBaseFactory.java,v
  retrieving revision 1.8.2.3
  retrieving revision 1.8.2.4
  diff -u -r1.8.2.3 -r1.8.2.4
  --- JavaBaseFactory.java	16 Aug 2004 22:57:48 -0000	1.8.2.3
  +++ JavaBaseFactory.java	24 Aug 2004 21:11:52 -0000	1.8.2.4
  @@ -16,8 +16,11 @@
    * limitations under the License.
    */
   
  +import java.util.Collections;
  +import java.util.HashMap;
   import java.util.Iterator;
   import java.util.List;
  +import java.util.Map;
   
   import org.apache.commons.lang.StringUtils;
   import org.apache.commons.logging.Log;
  @@ -48,6 +51,12 @@
       /** Logging */
       protected Log log = LogFactory.getLog(this.getClass());
   
  +    /**
  +     * A cache for previously obtained Class instances, which we keep in order
  +     * to reduce the Class.forName() overhead (which can be sizable).
  +     */
  +    private Map classCache = Collections.synchronizedMap(new HashMap());
  +    
       static
       {
           ObjectUtils.addOnce(packages, GenericLoader.getBasePackage());
  @@ -82,7 +91,12 @@
   
                   try
                   {
  -                    Class servClass = Class.forName(className.toString());
  +                    Class servClass = (Class) classCache.get(className);
  +                    if(servClass == null)
  +                    {
  +                        servClass = Class.forName(className.toString());
  +                        classCache.put(className, servClass);
  +                    }
                       assembler = (Assembler) servClass.newInstance();
                       break; // for()
                   }
  
  
  

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


Re: cvs commit: jakarta-turbine-2/src/java/org/apache/turbine/services/assemblerbroker/util/java JavaBaseFactory.java

Posted by "Henning P. Schmiedehausen" <hp...@intermeta.de>.
"Stephen McConnell" <mc...@apache.org> writes:

>What about using the context classloader - in my experience this is more
>reliable.  There is a good article about the differences here:

>http://www.javageeks.com/Papers/ClassForName/ClassForName.pdf

Hi,

that's an interesting paper. However, we have used Class.forName() at
this place before; that is something that I won't want to change
lightly between a RC2 and RC3 release.

I bookmarked it and will think about it for 2.3.2. We have many places
where Class.forName() is used in the Turbine code.

	Regards
		Henning

-- 
Dipl.-Inf. (Univ.) Henning P. Schmiedehausen          INTERMETA GmbH
hps@intermeta.de        +49 9131 50 654 0   http://www.intermeta.de/

RedHat Certified Engineer -- Jakarta Turbine Development  -- hero for hire
   Linux, Java, perl, Solaris -- Consulting, Training, Development

"Fighting for one's political stand is an honorable action, but re-
 fusing to acknowledge that there might be weaknesses in one's
 position - in order to identify them so that they can be remedied -
 is a large enough problem with the Open Source movement that it
 deserves to be on this list of the top five problems."
                       -- Michelle Levesque, "Fundamental Issues with
                                    Open Source Software Development"

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


RE: cvs commit: jakarta-turbine-2/src/java/org/apache/turbine/services/assemblerbroker/util/java JavaBaseFactory.java

Posted by Stephen McConnell <mc...@apache.org>.

> -----Original Message-----
> From: henning@apache.org [mailto:henning@apache.org]
>   +                    if(servClass == null)
>   +                    {
>   +                        servClass =
> Class.forName(className.toString());
>   +                        classCache.put(className, servClass);
>   +                    }

What about using the context classloader - in my experience this is more
reliable.  There is a good article about the differences here:

http://www.javageeks.com/Papers/ClassForName/ClassForName.pdf

Cheers, Steve.



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