You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tuscany.apache.org by rf...@apache.org on 2009/06/05 01:40:28 UTC
svn commit: r781871 - in /tuscany/branches/sca-java-1.x/modules/core/src:
main/java/org/apache/tuscany/sca/core/work/
test/java/org/apache/tuscany/sca/core/work/
Author: rfeng
Date: Thu Jun 4 23:40:28 2009
New Revision: 781871
URL: http://svn.apache.org/viewvc?rev=781871&view=rev
Log:
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.
Modified:
tuscany/branches/sca-java-1.x/modules/core/src/main/java/org/apache/tuscany/sca/core/work/DefaultWorkScheduler.java
tuscany/branches/sca-java-1.x/modules/core/src/main/java/org/apache/tuscany/sca/core/work/ThreadPoolWorkManager.java
tuscany/branches/sca-java-1.x/modules/core/src/test/java/org/apache/tuscany/sca/core/work/ThreadPoolWorkManagerTestCase.java
Modified: tuscany/branches/sca-java-1.x/modules/core/src/main/java/org/apache/tuscany/sca/core/work/DefaultWorkScheduler.java
URL: http://svn.apache.org/viewvc/tuscany/branches/sca-java-1.x/modules/core/src/main/java/org/apache/tuscany/sca/core/work/DefaultWorkScheduler.java?rev=781871&r1=781870&r2=781871&view=diff
==============================================================================
--- tuscany/branches/sca-java-1.x/modules/core/src/main/java/org/apache/tuscany/sca/core/work/DefaultWorkScheduler.java (original)
+++ tuscany/branches/sca-java-1.x/modules/core/src/main/java/org/apache/tuscany/sca/core/work/DefaultWorkScheduler.java Thu Jun 4 23:40:28 2009
@@ -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 @@
// // ignore
// }
if (jsr237WorkManager == null) {
- jsr237WorkManager = new ThreadPoolWorkManager(10);
+ jsr237WorkManager = new ThreadPoolWorkManager(0);
}
return jsr237WorkManager;
}
Modified: tuscany/branches/sca-java-1.x/modules/core/src/main/java/org/apache/tuscany/sca/core/work/ThreadPoolWorkManager.java
URL: http://svn.apache.org/viewvc/tuscany/branches/sca-java-1.x/modules/core/src/main/java/org/apache/tuscany/sca/core/work/ThreadPoolWorkManager.java?rev=781871&r1=781870&r2=781871&view=diff
==============================================================================
--- tuscany/branches/sca-java-1.x/modules/core/src/main/java/org/apache/tuscany/sca/core/work/ThreadPoolWorkManager.java (original)
+++ tuscany/branches/sca-java-1.x/modules/core/src/main/java/org/apache/tuscany/sca/core/work/ThreadPoolWorkManager.java Thu Jun 4 23:40:28 2009
@@ -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 @@
/**
* 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);
+ }
}
/**
Modified: tuscany/branches/sca-java-1.x/modules/core/src/test/java/org/apache/tuscany/sca/core/work/ThreadPoolWorkManagerTestCase.java
URL: http://svn.apache.org/viewvc/tuscany/branches/sca-java-1.x/modules/core/src/test/java/org/apache/tuscany/sca/core/work/ThreadPoolWorkManagerTestCase.java?rev=781871&r1=781870&r2=781871&view=diff
==============================================================================
--- tuscany/branches/sca-java-1.x/modules/core/src/test/java/org/apache/tuscany/sca/core/work/ThreadPoolWorkManagerTestCase.java (original)
+++ tuscany/branches/sca-java-1.x/modules/core/src/test/java/org/apache/tuscany/sca/core/work/ThreadPoolWorkManagerTestCase.java Thu Jun 4 23:40:28 2009
@@ -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 @@
/**
* This test case will test the ThreadPoolWorkManager
- *
+ *
* @version $Rev$ $Date$
*/
public class ThreadPoolWorkManagerTestCase {
@@ -130,7 +130,7 @@
}
/**
- * 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 @@
@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 @@
/**
* 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
*/