diff options
author | Thomas Watson | 2019-04-18 15:09:07 +0000 |
---|---|---|
committer | Thomas Watson | 2019-04-18 15:09:07 +0000 |
commit | ff70c66be91389ffb10151276725b21683f5fe64 (patch) | |
tree | e088c24b1e244f1274b1797716d8ad395bfdd28e | |
parent | 92e8d29b20e01924ed449c7e5c0f1bb7b96a151b (diff) | |
download | rt.equinox.framework-ff70c66be91389ffb10151276725b21683f5fe64.tar.gz rt.equinox.framework-ff70c66be91389ffb10151276725b21683f5fe64.tar.xz rt.equinox.framework-ff70c66be91389ffb10151276725b21683f5fe64.zip |
Bug 540507 - correctly determine pool size
Change-Id: Ic340f4d7b9f8c53065397f64d54d4cd141c3bfa1
2 files changed, 9 insertions, 6 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 795895916..294b3e69f 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 @@ -3626,7 +3626,7 @@ public class SystemBundleTests extends AbstractBundleTests { waitForStartLevel.await(10, TimeUnit.SECONDS); assertEquals("Did not finish start level setting.", 0, waitForStartLevel.getCount()); - assertEquals("Wrong number of start threads.", 6, startingThreads.size()); + assertEquals("Wrong number of start threads.", 5, startingThreads.size()); ListIterator<Bundle> itr = startingBundles.listIterator(); while (itr.hasNext()) { diff --git a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/framework/EquinoxContainerAdaptor.java b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/framework/EquinoxContainerAdaptor.java index b11297c55..cd589286c 100644 --- a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/framework/EquinoxContainerAdaptor.java +++ b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/framework/EquinoxContainerAdaptor.java @@ -134,12 +134,13 @@ public class EquinoxContainerAdaptor extends ModuleContainerAdaptor { } private Callable<Executor> createLazyExecutorCreator(EquinoxConfiguration config, final String threadName, int threadCnt) { - // use the number of processors - 1 because we use the current thread when rejected - final int maxThreads = threadCnt <= 0 ? Math.max(Runtime.getRuntime().availableProcessors() - 1, 1) : threadCnt; + // use the number of processors when configured value is <=0 + final int maxThreads = threadCnt <= 0 ? Runtime.getRuntime().availableProcessors() : threadCnt; return new Callable<Executor>() { @Override public Executor call() throws Exception { if (maxThreads == 1) { + // just do synchronous execution with current thread return new Executor() { @Override public void execute(Runnable command) { @@ -147,9 +148,11 @@ public class EquinoxContainerAdaptor extends ModuleContainerAdaptor { } }; } + // Decrement maxThreads by 1 for maxPoolSize because we use the current thread when max pool size is reached + int maxPoolSize = maxThreads - 1; // Always want to go to zero threads when idle int coreThreads = 0; - // idle timeout; make it short to get rid of threads quickly after resolve + // idle timeout; make it short to get rid of threads quickly after use int idleTimeout = 10; // use sync queue to force thread creation BlockingQueue<Runnable> queue = new SynchronousQueue<>(); @@ -162,14 +165,14 @@ public class EquinoxContainerAdaptor extends ModuleContainerAdaptor { return t; } }; - // use a rejection policy that simply runs the task in the current thread once the max threads is reached + // use a rejection policy that simply runs the task in the current thread once the max pool size is reached RejectedExecutionHandler rejectHandler = new RejectedExecutionHandler() { @Override public void rejectedExecution(Runnable r, ThreadPoolExecutor exe) { r.run(); } }; - return new ThreadPoolExecutor(coreThreads, maxThreads, idleTimeout, TimeUnit.SECONDS, queue, threadFactory, rejectHandler); + return new ThreadPoolExecutor(coreThreads, maxPoolSize, idleTimeout, TimeUnit.SECONDS, queue, threadFactory, rejectHandler); } }; } |