db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kahat...@apache.org
Subject svn commit: r789264 - /db/derby/code/trunk/java/engine/org/apache/derby/impl/services/monitor/TopService.java
Date Mon, 29 Jun 2009 08:58:33 GMT
Author: kahatlen
Date: Mon Jun 29 08:58:33 2009
New Revision: 789264

URL: http://svn.apache.org/viewvc?rev=789264&view=rev
Log:
DERBY-4018: ArrayIndexOutOfBoundsException in TopService.inService under heavy multithreaded
use of EmbeddedDriver

Factored out two for loops and surrounded them with synchronization on
the vector they were iterating over. This prevent others from changing
the size of the vector between the calls to Vector.size() and
Vector.get().

Modified:
    db/derby/code/trunk/java/engine/org/apache/derby/impl/services/monitor/TopService.java

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/services/monitor/TopService.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/services/monitor/TopService.java?rev=789264&r1=789263&r2=789264&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/services/monitor/TopService.java
(original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/services/monitor/TopService.java
Mon Jun 29 08:58:33 2009
@@ -102,14 +102,11 @@
 
 	void setTopModule(Object instance) {
 		synchronized (this) {
-			for (int i = 0; i < moduleInstances.size(); i++) {
-				ModuleInstance module = (ModuleInstance) moduleInstances.elementAt(i);
-				if (module.getInstance() == instance) {
-					topModule = module;
-					notifyAll();
-					break;
-				}
-			}
+            ModuleInstance module = findModuleInstance(instance);
+            if (module != null) {
+                topModule = module;
+                notifyAll();
+            }
 
 			// now add an additional entry into the hashtable
 			// that maps the server name as seen by the user
@@ -223,6 +220,26 @@
 		return null;
 	}
 
+    /**
+     * Find a {@code ModuleInstance} object whose {@code getInstance()} method
+     * returns the object specified by the {@code instance} parameter.
+     *
+     * @param instance the instance to look for
+     * @return a {@code ModuleInstance} object, or {@code null} if no match
+     * was found
+     */
+    private ModuleInstance findModuleInstance(Object instance) {
+        synchronized (moduleInstances) {
+            for (int i = 0; i < moduleInstances.size(); i++) {
+                ModuleInstance module = (ModuleInstance) moduleInstances.get(i);
+                if (module.getInstance() == instance) {
+                    return module;
+                }
+            }
+        }
+        return null;
+    }
+
 	/**
 		Boot a module, performs three steps.
 
@@ -394,14 +411,7 @@
 	}
 
 	boolean inService(Object instance) {
-
-		for (int i = 0; i < moduleInstances.size(); i++) {
-
-			ModuleInstance mi = (ModuleInstance) moduleInstances.elementAt(i);
-			if (mi.getInstance() == instance)
-				return true;
-		}
-		return false;
+        return findModuleInstance(instance) != null;
 	}
 
 	public ProtocolKey getKey() {



Mime
View raw message