Author: rickhall
Date: Thu Mar 10 21:11:07 2011
New Revision: 1080350
URL: http://svn.apache.org/viewvc?rev=1080350&view=rev
Log:
Move thread for shutting down framework further out to avoid
potential deadlock when a bundle tries to stop the framework
during framework startup. (FELIX-1816)
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=1080350&r1=1080349&r2=1080350&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 Mar 10 21:11:07 2011
@@ -162,8 +162,7 @@ public class Felix extends BundleImpl im
private final String[] m_bootPkgs;
private final boolean[] m_bootPkgWildcards;
- // Shutdown thread.
- private Thread m_shutdownThread = null;
+ // Shutdown gate.
private volatile ThreadGate m_shutdownGate = null;
// Security Manager created by the framework
@@ -867,7 +866,24 @@ public class Felix extends BundleImpl im
AdminPermission.EXECUTE));
}
- stopBundle(this, true);
+ // Spec says stop() on SystemBundle should return immediately and
+ // shutdown framework on another thread.
+ new Thread(new Runnable() {
+ public void run()
+ {
+ try
+ {
+ stopBundle(Felix.this, true);
+ }
+ catch (BundleException ex)
+ {
+ m_logger.log(
+ Logger.LOG_ERROR,
+ "Exception trying to stop framework.",
+ ex);
+ }
+ }
+ }, "FelixShutdown").start();
}
public void stop(int options) throws BundleException
@@ -4370,7 +4386,7 @@ public class Felix extends BundleImpl im
}
}
- class SystemBundleActivator implements BundleActivator, Runnable
+ class SystemBundleActivator implements BundleActivator
{
public void start(BundleContext context) throws Exception
{
@@ -4391,18 +4407,6 @@ public class Felix extends BundleImpl im
public void stop(BundleContext context)
{
- // Spec says stop() on SystemBundle should return immediately and
- // shutdown framework on another thread.
- if (m_shutdownThread == null)
- {
- // Initial call of stop, so kick off shutdown.
- m_shutdownThread = new Thread(this, "FelixShutdown");
- m_shutdownThread.start();
- }
- }
-
- public void run()
- {
// The state of the framework should be STOPPING, so
// acquire the bundle lock to verify it.
acquireBundleLock(Felix.this, Bundle.STOPPING);
@@ -4522,7 +4526,6 @@ public class Felix extends BundleImpl im
setBundleStateAndNotify(Felix.this, Bundle.RESOLVED);
m_shutdownGate.open();
m_shutdownGate = null;
- m_shutdownThread = null;
}
finally
{