Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Watson2016-09-27 21:58:53 +0000
committerThomas Watson2016-09-27 21:58:53 +0000
commit711ff81d73350c6492b5acc96cc4cddc6906f30f (patch)
tree3f2f2cb85f9d0bc3bb3db1adcc270bc738273040
parent3fe546d7f67aeaa04c91851b40c53e6cccaf94fa (diff)
downloadrt.equinox.framework-711ff81d73350c6492b5acc96cc4cddc6906f30f.tar.gz
rt.equinox.framework-711ff81d73350c6492b5acc96cc4cddc6906f30f.tar.xz
rt.equinox.framework-711ff81d73350c6492b5acc96cc4cddc6906f30f.zip
Bug 502318 - osgi.framework.activeThreadType is no longer usedY20160929-1000
Change-Id: I54fa1cce33e778d02a792b7c24a651c30555d08e Signed-off-by: Thomas Watson <tjwatson@us.ibm.com>
-rwxr-xr-xbundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/bundles/SystemBundleTests.java54
-rw-r--r--bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/framework/EquinoxConfiguration.java3
-rw-r--r--bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/framework/EquinoxContainer.java9
3 files changed, 64 insertions, 2 deletions
diff --git a/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/bundles/SystemBundleTests.java b/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/bundles/SystemBundleTests.java
index 07f7f7ff8..68b422ff3 100755
--- a/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/bundles/SystemBundleTests.java
+++ b/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/bundles/SystemBundleTests.java
@@ -2900,4 +2900,58 @@ public class SystemBundleTests extends AbstractBundleTests {
assertEquals("Wrong state for SystemBundle", Bundle.RESOLVED, equinox.getState()); //$NON-NLS-1$
}
+ public void testDaemonActiveThread() throws BundleException, InterruptedException {
+ File config = OSGiTestsActivator.getContext().getDataFile(getName());
+ config.mkdirs();
+ Map<String, Object> configuration = new HashMap<String, Object>();
+ configuration.put(Constants.FRAMEWORK_STORAGE, config.getAbsolutePath());
+
+ // test setting to anything other than 'normal'
+ // should result in a daemon thread
+ configuration.put(EquinoxConfiguration.PROP_ACTIVE_THREAD_TYPE, "daemon");
+ Equinox equinox = new Equinox(configuration);
+ equinox.start();
+ checkActiveThreadType(equinox, true);
+ equinox.stop();
+ equinox.waitForStop(10000);
+
+ // test setting to 'normal'
+ // should result in a non-daemon thread
+ configuration.put(EquinoxConfiguration.PROP_ACTIVE_THREAD_TYPE, EquinoxConfiguration.ACTIVE_THREAD_TYPE_NORMAL);
+ equinox = new Equinox(configuration);
+ equinox.start();
+ checkActiveThreadType(equinox, false);
+ equinox.stop();
+ equinox.waitForStop(10000);
+
+ // test setting to null (default)
+ // should result in a non-daemon thread
+ configuration.remove(EquinoxConfiguration.PROP_ACTIVE_THREAD_TYPE);
+ equinox = new Equinox(configuration);
+ equinox.start();
+ checkActiveThreadType(equinox, false);
+ equinox.stop();
+ }
+
+ void checkActiveThreadType(Equinox equinox, boolean expectIsDeamon) {
+ String uuid = equinox.getBundleContext().getProperty(Constants.FRAMEWORK_UUID);
+ ThreadGroup topGroup = Thread.currentThread().getThreadGroup();
+ if (topGroup != null) {
+ while (topGroup.getParent() != null) {
+ topGroup = topGroup.getParent();
+ }
+ }
+ Thread[] threads = new Thread[topGroup.activeCount()];
+ topGroup.enumerate(threads);
+ Thread found = null;
+ for (Thread t : threads) {
+ String name = t.getName();
+ if (("Active Thread: Equinox Container: " + uuid).equals(name)) {
+ found = t;
+ break;
+ }
+ }
+ assertNotNull("No framework active thread for \"" + uuid + "\" found in : " + Arrays.toString(threads), found);
+ assertEquals("Wrong daemon type.", expectIsDeamon, found.isDaemon());
+ }
}
diff --git a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/framework/EquinoxConfiguration.java b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/framework/EquinoxConfiguration.java
index c82fc7201..619a1c0e6 100644
--- a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/framework/EquinoxConfiguration.java
+++ b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/framework/EquinoxConfiguration.java
@@ -209,6 +209,9 @@ public class EquinoxConfiguration implements EnvironmentInfo {
public static final Collection<String> PROP_WITH_ECLIPSE_STARTER_DEFAULTS = Collections.singletonList(PROP_COMPATIBILITY_BOOTDELEGATION);
public static final String PROP_INIT_UUID = "equinox.init.uuid"; //$NON-NLS-1$
+ public static final String PROP_ACTIVE_THREAD_TYPE = "osgi.framework.activeThreadType"; //$NON-NLS-1$
+ public static final String ACTIVE_THREAD_TYPE_NORMAL = "normal"; //$NON-NLS-1$
+
public static final class ConfigValues {
/**
* Value of {@link #localConfig} properties that should be considered
diff --git a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/framework/EquinoxContainer.java b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/framework/EquinoxContainer.java
index def3ffde7..87011f38b 100644
--- a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/framework/EquinoxContainer.java
+++ b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/framework/EquinoxContainer.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2012, 2015 IBM Corporation and others.
+ * Copyright (c) 2012, 2016 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -272,8 +272,13 @@ public class EquinoxContainer implements ThreadFactory, Runnable {
@Override
public Thread newThread(Runnable r) {
+ String type = equinoxConfig.getConfiguration(EquinoxConfiguration.PROP_ACTIVE_THREAD_TYPE, EquinoxConfiguration.ACTIVE_THREAD_TYPE_NORMAL);
Thread t = new Thread(r, "Active Thread: " + toString()); //$NON-NLS-1$
- t.setDaemon(false);
+ if (EquinoxConfiguration.ACTIVE_THREAD_TYPE_NORMAL.equals(type)) {
+ t.setDaemon(false);
+ } else {
+ t.setDaemon(true);
+ }
t.setPriority(Thread.NORM_PRIORITY);
return t;
}

Back to the top