felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rickh...@apache.org
Subject svn commit: r767850 - /felix/trunk/framework/src/main/java/org/apache/felix/framework/Felix.java
Date Thu, 23 Apr 2009 08:34:42 GMT
Author: rickhall
Date: Thu Apr 23 08:34:41 2009
New Revision: 767850

URL: http://svn.apache.org/viewvc?rev=767850&view=rev
Log:
Need to double-check wires for dynamic imports because it is possible
that threads can race to concurrently create dynamically imported wires.
This ensures that the second thread will see the wire created by the
first thread. (FELIX-1027)

Modified:
    felix/trunk/framework/src/main/java/org/apache/felix/framework/Felix.java

Modified: felix/trunk/framework/src/main/java/org/apache/felix/framework/Felix.java
URL: http://svn.apache.org/viewvc/felix/trunk/framework/src/main/java/org/apache/felix/framework/Felix.java?rev=767850&r1=767849&r2=767850&view=diff
==============================================================================
--- felix/trunk/framework/src/main/java/org/apache/felix/framework/Felix.java (original)
+++ felix/trunk/framework/src/main/java/org/apache/felix/framework/Felix.java Thu Apr 23 08:34:41
2009
@@ -3716,6 +3716,19 @@
 
                 try
                 {
+                    // Double check to make sure that someone hasn't beaten us to
+                    // dynamically importing the package, which can happen if two
+                    // threads are racing to do so. If we have an existing wire,
+                    // then just return it instead.
+                    IWire[] wires = importer.getWires();
+                    for (int i = 0; (wires != null) && (i < wires.length); i++)
+                    {
+                        if (wires[i].hasPackage(pkgName))
+                        {
+                            return wires[i];
+                        }
+                    }
+
                     Object[] result = m_resolver.resolveDynamicImport(m_resolverState, importer,
pkgName);
                     if (result != null)
                     {
@@ -3728,7 +3741,7 @@
                         // Dynamically add new wire to importing module.
                         if (candidateWire != null)
                         {
-                            IWire[] wires = importer.getWires();
+                            wires = importer.getWires();
                             IWire[] newWires = null;
                             if (wires == null)
                             {



Mime
View raw message