harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ton...@apache.org
Subject svn commit: r548246 - in /harmony/enhanced/classlib/trunk/modules/jndi/src/main/java: javax/naming/spi/ org/apache/harmony/jndi/provider/dns/
Date Mon, 18 Jun 2007 07:38:48 GMT
Author: tonywu
Date: Mon Jun 18 00:38:47 2007
New Revision: 548246

URL: http://svn.apache.org/viewvc?view=rev&rev=548246
Log:
Apply patch HARMONY-4201 ([classlib][jndi] Performance improvement for JNDI module)

Modified:
    harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/javax/naming/spi/NamingManager.java
    harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/dns/Resolver.java
    harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/dns/ResolverCache.java
    harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/dns/SList.java

Modified: harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/javax/naming/spi/NamingManager.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/javax/naming/spi/NamingManager.java?view=diff&rev=548246&r1=548245&r2=548246
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/javax/naming/spi/NamingManager.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/javax/naming/spi/NamingManager.java
Mon Jun 18 00:38:47 2007
@@ -106,7 +106,7 @@
     static InitialContextFactoryBuilder icfb;
 
     static ObjectFactoryBuilder ofb;
-
+    
     NamingManager() {
         super();
         // package private to prevent it being instanced but make it can be
@@ -129,22 +129,21 @@
      * @throws NamingException
      *             for other errors encountered.
      */
-    public static synchronized void setInitialContextFactoryBuilder(
+    public static  void setInitialContextFactoryBuilder(
             InitialContextFactoryBuilder icfb) throws IllegalStateException,
             SecurityException, NamingException {
-
-        if (null != NamingManager.icfb) {
-            // jndi.1E=InitialContextFactoryBuilder cannot be reset
-            throw new IllegalStateException(Messages.getString("jndi.1E"));  //$NON-NLS-1$
-        }
-
         // check security access
         SecurityManager sm = System.getSecurityManager();
         if (null != sm) {
             sm.checkSetFactory();
         }
-
-        NamingManager.icfb = icfb;
+        synchronized (NamingManager.class) {
+            if (null != NamingManager.icfb) {
+                // jndi.1E=InitialContextFactoryBuilder cannot be reset
+                throw new IllegalStateException(Messages.getString("jndi.1E")); //$NON-NLS-1$
+            }
+            NamingManager.icfb = icfb;
+        }
     }
 
     /**

Modified: harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/dns/Resolver.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/dns/Resolver.java?view=diff&rev=548246&r1=548245&r2=548246
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/dns/Resolver.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/dns/Resolver.java
Mon Jun 18 00:38:47 2007
@@ -25,6 +25,7 @@
 
 import java.net.InetAddress;
 import java.net.SocketTimeoutException;
+import java.util.ArrayList;
 import java.util.Enumeration;
 import java.util.HashSet;
 import java.util.Hashtable;
@@ -33,7 +34,6 @@
 import java.util.Set;
 import java.util.StringTokenizer;
 import java.util.Vector;
-//import java.util.logging.Level;
 
 import javax.naming.NameNotFoundException;
 import javax.naming.NamingException;
@@ -99,9 +99,9 @@
     private int threadNumberLimit;
     
     // vector with currently running Resolver threads 
-    private final Vector<ThreadListEntry> resolverThreads = new Vector<ThreadListEntry>();
+    private final ArrayList<ThreadListEntry> resolverThreads = new ArrayList<ThreadListEntry>();
     // the list of host names that should be resolved
-    private final Vector<ThreadListEntry> hostnamesToResolve = new Vector<ThreadListEntry>();
+    private final ArrayList<ThreadListEntry> hostnamesToResolve = new ArrayList<ThreadListEntry>();
     // semaphore that controls access to both lists above
     private class ThreadListSemaphore {}
     private final Object threadListSemaphore = new ThreadListSemaphore();
@@ -1428,7 +1428,7 @@
         synchronized (threadListSemaphore) {
             // check that no currently running thread looks for this hostname 
             for (int i = 0; i < resolverThreads.size(); i++) {
-                Resolver.ThreadListEntry entry = resolverThreads.elementAt(i);
+                Resolver.ThreadListEntry entry = resolverThreads.get(i);
                 if (ProviderMgr.namesAreEqual(hostname,
                                               entry.serverNameToResolve) &&
                     entry.dnsClass == dnsClass)
@@ -1440,7 +1440,7 @@
             }
             // check if the hostname is already scheduled for resolving
             for (int i = 0; i < hostnamesToResolve.size(); i++) {
-                Resolver.ThreadListEntry entry = hostnamesToResolve.elementAt(i);
+                Resolver.ThreadListEntry entry = hostnamesToResolve.get(i);
                 if (ProviderMgr.namesAreEqual(hostname,
                                               entry.serverNameToResolve) &&
                     entry.dnsClass == dnsClass)
@@ -1459,7 +1459,7 @@
             newEntry = new Resolver.ThreadListEntry();
             newEntry.serverNameToResolve = hostname;
             newEntry.dnsClass = dnsClass;
-            hostnamesToResolve.addElement(newEntry);
+            hostnamesToResolve.add(newEntry);
             // starting new thread that should make further updates by itself
             newThread = new Thread(this);
             //if (LogConst.DEBUG) {                            
@@ -1483,10 +1483,10 @@
         // update lists
         synchronized (threadListSemaphore) {
             if (hostnamesToResolve.size() > 0) {
-                entryToProcess = hostnamesToResolve.elementAt(0);
+                entryToProcess = hostnamesToResolve.get(0);
                 hostnamesToResolve.remove(0);
                 entryToProcess.thread = Thread.currentThread();
-                resolverThreads.addElement(entryToProcess);
+                resolverThreads.add(entryToProcess);
             } else {
                 //ProviderMgr.logger.warning(
                 //        "Resolver thread: no host name to resolve");
@@ -1515,7 +1515,7 @@
         // update resolver threads list, remove info about current thread
         synchronized (threadListSemaphore) {
             for (int i = 0; i < resolverThreads.size(); i++) {
-                Resolver.ThreadListEntry entry = resolverThreads.elementAt(i);
+                Resolver.ThreadListEntry entry = resolverThreads.get(i);
 
                 if (ProviderMgr.namesAreEqual(
                         entryToProcess.serverNameToResolve,

Modified: harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/dns/ResolverCache.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/dns/ResolverCache.java?view=diff&rev=548246&r1=548245&r2=548246
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/dns/ResolverCache.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/dns/ResolverCache.java
Mon Jun 18 00:38:47 2007
@@ -24,7 +24,7 @@
 package org.apache.harmony.jndi.provider.dns;
 
 import java.util.Enumeration;
-import java.util.Hashtable;
+import java.util.HashMap;
 import java.util.Vector;
 
 /**
@@ -37,14 +37,14 @@
 class ResolverCache {
 
     /** keys - zone & host names; values - vectors with RRs */
-    Hashtable<String, Vector<CacheEntry>> names = new Hashtable<String, Vector<CacheEntry>>();
+    HashMap<String, Vector<CacheEntry>> names = new HashMap<String, Vector<CacheEntry>>();
 
     /** 
      * Since <code>ResolverCache</code> is singleton class its constructor
      *  should be hidden.
      */
     private ResolverCache() {
-        names = new Hashtable<String, Vector<CacheEntry>>();
+        names = new HashMap<String, Vector<CacheEntry>>();
     }
 
     private static ResolverCache instance = null;
@@ -146,7 +146,7 @@
      * Removes all cached entries.
      */
     synchronized void clear() {
-        names = new Hashtable<String, Vector<CacheEntry>>();
+        names = new HashMap<String, Vector<CacheEntry>>();
     }
 
     // additional class

Modified: harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/dns/SList.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/dns/SList.java?view=diff&rev=548246&r1=548245&r2=548246
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/dns/SList.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/dns/SList.java
Mon Jun 18 00:38:47 2007
@@ -23,9 +23,9 @@
 
 package org.apache.harmony.jndi.provider.dns;
 
-import java.util.Vector;
-import java.util.Hashtable;
 import java.util.Enumeration;
+import java.util.Hashtable;
+import java.util.Vector;
 
 import org.apache.harmony.jndi.internal.nls.Messages;
 
@@ -60,16 +60,13 @@
         servers = new Vector<Server>();
     }
 
-    private static SList instance = null;
+    private static SList instance = new SList();
 
     /**
      * <code>SList</code> is a singleton class.
      * @return instance of <code>SList</code>
      */
     static SList getInstance() {
-        if (instance == null) {
-            instance = new SList();
-        }
         return instance;
     }
 



Mime
View raw message