felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fmesc...@apache.org
Subject svn commit: r662733 - /felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/AbstractComponentManager.java
Date Tue, 03 Jun 2008 10:22:33 GMT
Author: fmeschbe
Date: Tue Jun  3 03:22:33 2008
New Revision: 662733

URL: http://svn.apache.org/viewvc?rev=662733&view=rev
Log:
FELIX-490 Do not synchronously deactivate a component if it is currently
being activated. Instead schedule deactivation to prevent a deadlock.

Modified:
    felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/AbstractComponentManager.java

Modified: felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/AbstractComponentManager.java
URL: http://svn.apache.org/viewvc/felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/AbstractComponentManager.java?rev=662733&r1=662732&r2=662733&view=diff
==============================================================================
--- felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/AbstractComponentManager.java
(original)
+++ felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/AbstractComponentManager.java
Tue Jun  3 03:22:33 2008
@@ -163,7 +163,7 @@
     public final void reactivate()
     {
         // synchronously deactivate and schedule activation asynchronously
-        deactivateInternal();
+        deactivate();
 
         getActivator().schedule( new Runnable()
         {
@@ -181,11 +181,37 @@
      * This method unlike other state change methods immediately takes
      * action and deactivates the component. The reason for this is, that this
      * method is called when a required service is not available any more and
-     * hence the component cannot work.
+     * hence the component cannot work. The exception to this is, that the
+     * deactivation is scheduled for asynchronous execution if the component
+     * is currently activating.
+     * <p>
+     * We must not immediately deactivate while the component is activating
+     * because we might create a deadlock: If this method is called from the
+     * framework service event thread some locks may be held. If at the same
+     * time the activation tries to access referenced services the framework
+     * lock will be tried to be obtained. On the other hand the activation
+     * holds a lock on this instance and the deactivation tries to get that
+     * lock.
      */
     public final void deactivate()
     {
-        deactivateInternal();
+        if ( getState() == STATE_ACTIVATING )
+        {
+            log( LogService.LOG_WARNING,
+                "Asynchronously deactivating the component to prevent a deadlock while it
is being activated",
+                m_componentMetadata, null );
+            getActivator().schedule( new Runnable()
+            {
+                public void run()
+                {
+                    deactivateInternal();
+                }
+            } );
+        }
+        else
+        {
+            deactivateInternal();
+        }
     }
 
 



Mime
View raw message