diff options
author | rfeng <rfeng@13f79535-47bb-0310-9956-ffa450edef68> | 2009-06-04 23:40:28 +0000 |
---|---|---|
committer | rfeng <rfeng@13f79535-47bb-0310-9956-ffa450edef68> | 2009-06-04 23:40:28 +0000 |
commit | ffe36f15ffc3cb9115e25ed24e9208aa8d8642f9 (patch) | |
tree | 2c048e058be16bf312e3e85dc664e41af17db9d8 /branches/sca-java-1.x/modules/core/src | |
parent | b921d97c9a71c417d443fb79f28675c587a80958 (diff) |
Fix for TUSCANY-3076. The DefaultWorkScheduler only has 10 threads in the pool and it causes deadlock. With this fix, it's default to a cached pool which expand/thrink on demand.
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@781871 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'branches/sca-java-1.x/modules/core/src')
3 files changed, 25 insertions, 30 deletions
diff --git a/branches/sca-java-1.x/modules/core/src/main/java/org/apache/tuscany/sca/core/work/DefaultWorkScheduler.java b/branches/sca-java-1.x/modules/core/src/main/java/org/apache/tuscany/sca/core/work/DefaultWorkScheduler.java index 2085a796ab..55b0acded9 100644 --- a/branches/sca-java-1.x/modules/core/src/main/java/org/apache/tuscany/sca/core/work/DefaultWorkScheduler.java +++ b/branches/sca-java-1.x/modules/core/src/main/java/org/apache/tuscany/sca/core/work/DefaultWorkScheduler.java @@ -6,15 +6,15 @@ * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations - * under the License. + * under the License. */ package org.apache.tuscany.sca.core.work; @@ -62,7 +62,7 @@ public class DefaultWorkScheduler implements WorkScheduler { // // ignore // } if (jsr237WorkManager == null) { - jsr237WorkManager = new ThreadPoolWorkManager(10); + jsr237WorkManager = new ThreadPoolWorkManager(0); } return jsr237WorkManager; } diff --git a/branches/sca-java-1.x/modules/core/src/main/java/org/apache/tuscany/sca/core/work/ThreadPoolWorkManager.java b/branches/sca-java-1.x/modules/core/src/main/java/org/apache/tuscany/sca/core/work/ThreadPoolWorkManager.java index dad5968f65..91d00a58d9 100644 --- a/branches/sca-java-1.x/modules/core/src/main/java/org/apache/tuscany/sca/core/work/ThreadPoolWorkManager.java +++ b/branches/sca-java-1.x/modules/core/src/main/java/org/apache/tuscany/sca/core/work/ThreadPoolWorkManager.java @@ -6,15 +6,15 @@ * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations - * under the License. + * under the License. */ package org.apache.tuscany.sca.core.work; @@ -51,24 +51,24 @@ public class ThreadPoolWorkManager { /** * Initializes the thread-pool. * - * @param threadPoolSize Thread-pool size. - * @throws IllegalArgumentException if threadPoolSize < 1 + * @param threadPoolSize Thread-pool size. If the size <1, then a cached pool is created */ public ThreadPoolWorkManager(int threadPoolSize) { - if (threadPoolSize < 1) { - throw new IllegalArgumentException("Invalid threadPoolSize of " - + threadPoolSize + ". It must be >= 1"); - } - - // Creates a new Executor, use a custom ThreadFactory that - // creates daemon threads. - executor = Executors.newFixedThreadPool(threadPoolSize, new ThreadFactory() { + ThreadFactory factory = new ThreadFactory() { public Thread newThread(Runnable r) { Thread thread = new Thread(r); thread.setDaemon(true); return thread; } - }); + }; + if (threadPoolSize <= 1) { + + // Creates a new Executor, use a custom ThreadFactory that + // creates daemon threads. + executor = Executors.newCachedThreadPool(factory); + } else { + executor = Executors.newFixedThreadPool(threadPoolSize); + } } /** diff --git a/branches/sca-java-1.x/modules/core/src/test/java/org/apache/tuscany/sca/core/work/ThreadPoolWorkManagerTestCase.java b/branches/sca-java-1.x/modules/core/src/test/java/org/apache/tuscany/sca/core/work/ThreadPoolWorkManagerTestCase.java index 715f5f95c0..9e5b8d035e 100644 --- a/branches/sca-java-1.x/modules/core/src/test/java/org/apache/tuscany/sca/core/work/ThreadPoolWorkManagerTestCase.java +++ b/branches/sca-java-1.x/modules/core/src/test/java/org/apache/tuscany/sca/core/work/ThreadPoolWorkManagerTestCase.java @@ -6,15 +6,15 @@ * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations - * under the License. + * under the License. */ package org.apache.tuscany.sca.core.work; @@ -25,7 +25,7 @@ import org.junit.Test; /** * This test case will test the ThreadPoolWorkManager - * + * * @version $Rev$ $Date$ */ public class ThreadPoolWorkManagerTestCase { @@ -130,7 +130,7 @@ public class ThreadPoolWorkManagerTestCase { } /** - * Tests running a mixture of fast and slow jobs some of which fail on the + * Tests running a mixture of fast and slow jobs some of which fail on the * ThreadPoolWorkManager */ @Test @@ -170,12 +170,7 @@ public class ThreadPoolWorkManagerTestCase { @Test public void testThreadPoolWorkManagerLessThan1Size() { for (int i = 0; i >= -10; i--) { - try { - new ThreadPoolWorkManager(i); - Assert.fail("Should have thrown IllegalArgumentException"); - } catch (IllegalArgumentException ex) { - Assert.assertTrue(ex.toString().indexOf(Integer.toString(i)) != -1); - } + new ThreadPoolWorkManager(i); } } @@ -215,7 +210,7 @@ public class ThreadPoolWorkManagerTestCase { /** * Waits for the specified number of jobs to complete or the timeout to fire. - * + * * @param listener The listener to use to track Work unit completion * @param completedWorkItemsToWaitFor The number of Work items to complete */ |