[jboss-osgi-commits] JBoss-OSGI SVN: r90964 - projects/jboss-osgi/projects/runtime/felix/trunk/src/main/java/org/jboss/osgi/felix/framework.

jboss-osgi-commits at lists.jboss.org jboss-osgi-commits at lists.jboss.org
Wed Jul 8 18:17:32 EDT 2009


Author: thomas.diesler at jboss.com
Date: 2009-07-08 18:17:32 -0400 (Wed, 08 Jul 2009)
New Revision: 90964

Modified:
   projects/jboss-osgi/projects/runtime/felix/trunk/src/main/java/org/jboss/osgi/felix/framework/FelixIntegration.java
Log:
[FELIX-1311] Felix shutdown may lead to dead lock

Modified: projects/jboss-osgi/projects/runtime/felix/trunk/src/main/java/org/jboss/osgi/felix/framework/FelixIntegration.java
===================================================================
--- projects/jboss-osgi/projects/runtime/felix/trunk/src/main/java/org/jboss/osgi/felix/framework/FelixIntegration.java	2009-07-08 22:03:40 UTC (rev 90963)
+++ projects/jboss-osgi/projects/runtime/felix/trunk/src/main/java/org/jboss/osgi/felix/framework/FelixIntegration.java	2009-07-08 22:17:32 UTC (rev 90964)
@@ -186,21 +186,53 @@
    {
       if (framework != null)
       {
-         try
+         // Running the Felix shutdown in a separate thread that gets 
+         // interrupted after a 10sec timeout. This is a workaround for
+         //
+         // [FELIX-1311] Felix shutdown may lead to dead lock
+         // https://issues.apache.org/jira/browse/FELIX-1311
+         Runnable runnable = new Runnable()
          {
-            framework.stop();
-            framework.waitForStop(5000);
-            framework = null;
-            log.debug("SystemBundle STOPPED");
-         }
-         catch (BundleException ex)
+            public void run()
+            {
+               try
+               {
+                  framework.stop();
+                  framework.waitForStop(5000);
+                  framework = null;
+                  log.debug("SystemBundle STOPPED");
+               }
+               catch (BundleException ex)
+               {
+                  log.error("Cannot stop Felix", ex);
+               }
+               catch (InterruptedException ex)
+               {
+                  log.error("Cannot stop Felix", ex);
+               }
+            }
+         };
+         
+         Thread thread = new Thread(runnable);
+         thread.start();
+
+         int sleep = 500;
+         int timeout = 10000;
+         while (framework != null && timeout > 0)
          {
-            log.error("Cannot stop Felix", ex);
+            try
+            {
+               Thread.sleep(sleep);
+               timeout -= sleep;
+            }
+            catch (InterruptedException ex)
+            {
+               // ignore
+            }
          }
-         catch (InterruptedException ex)
-         {
-            log.error("Cannot stop Felix", ex);
-         }
+         
+         if (timeout == 0 && thread.isAlive())
+            thread.interrupt();
       }
    }
 




More information about the jboss-osgi-commits mailing list