hadoop-common-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cutt...@apache.org
Subject svn commit: r496899 - in /lucene/hadoop/trunk: CHANGES.txt src/java/org/apache/hadoop/metrics/ContextFactory.java
Date Wed, 17 Jan 2007 00:11:43 GMT
Author: cutting
Date: Tue Jan 16 16:11:43 2007
New Revision: 496899

URL: http://svn.apache.org/viewvc?view=rev&rev=496899
Log:
HADOOP-886.  Reduce number of timer threads created by metrics API by pooling contexts.  Contributed
by Nigel.

Modified:
    lucene/hadoop/trunk/CHANGES.txt
    lucene/hadoop/trunk/src/java/org/apache/hadoop/metrics/ContextFactory.java

Modified: lucene/hadoop/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/hadoop/trunk/CHANGES.txt?view=diff&rev=496899&r1=496898&r2=496899
==============================================================================
--- lucene/hadoop/trunk/CHANGES.txt (original)
+++ lucene/hadoop/trunk/CHANGES.txt Tue Jan 16 16:11:43 2007
@@ -32,6 +32,9 @@
     An exception is still thrown, but corrupt blocks are now removed
     when they have replicas.  (Wendy Chien via cutting)
 
+ 9. HADOOP-886.  Reduce number of timer threads created by metrics API
+    by pooling contexts.  (Nigel Daley via cutting)
+
 
 Release 0.10.1 - 2007-01-10
 

Modified: lucene/hadoop/trunk/src/java/org/apache/hadoop/metrics/ContextFactory.java
URL: http://svn.apache.org/viewvc/lucene/hadoop/trunk/src/java/org/apache/hadoop/metrics/ContextFactory.java?view=diff&rev=496899&r1=496898&r2=496899
==============================================================================
--- lucene/hadoop/trunk/src/java/org/apache/hadoop/metrics/ContextFactory.java (original)
+++ lucene/hadoop/trunk/src/java/org/apache/hadoop/metrics/ContextFactory.java Tue Jan 16
16:11:43 2007
@@ -45,6 +45,7 @@
     
     // private Map<String,Object> attributeMap = new HashMap<String,Object>();
     private Map attributeMap = new HashMap();
+    private Map<String,MetricsContext> contextMap = new HashMap<String,MetricsContext>();
     
     /** Creates a new instance of ContextFactory */
     protected ContextFactory() {
@@ -112,9 +113,10 @@
      * @param contextName the name of the context
      * @return the named MetricsContext
      */
-    public MetricsContext getContext(String contextName) 
+    public synchronized MetricsContext getContext(String contextName) 
         throws IOException, ClassNotFoundException, InstantiationException, IllegalAccessException
     {
+        if (contextMap.containsKey(contextName)) return contextMap.get(contextName);
         String classNameAttribute = contextName + CONTEXT_CLASS_SUFFIX;
         String className = (String) getAttribute(classNameAttribute);
         if (className == null) {
@@ -124,6 +126,7 @@
         AbstractMetricsContext metricsContext = 
                 (AbstractMetricsContext) contextClass.newInstance();
         metricsContext.init(contextName, this);
+        contextMap.put(contextName, metricsContext);
         return metricsContext;
     }
     



Mime
View raw message