Author: manik.surtani(a)jboss.com
Date: 2009-01-19 08:18:35 -0500 (Mon, 19 Jan 2009)
New Revision: 7509
Modified:
core/branches/flat/src/main/java/org/horizon/executors/DefaultExecutorFactory.java
core/branches/flat/src/main/java/org/horizon/executors/DefaultScheduledExecutorFactory.java
Log:
Updated default executors to use a queue size
Modified:
core/branches/flat/src/main/java/org/horizon/executors/DefaultExecutorFactory.java
===================================================================
---
core/branches/flat/src/main/java/org/horizon/executors/DefaultExecutorFactory.java 2009-01-19
11:06:16 UTC (rev 7508)
+++
core/branches/flat/src/main/java/org/horizon/executors/DefaultExecutorFactory.java 2009-01-19
13:18:35 UTC (rev 7509)
@@ -4,8 +4,10 @@
import java.util.Properties;
import java.util.concurrent.ExecutorService;
-import java.util.concurrent.Executors;
+import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadFactory;
+import java.util.concurrent.ThreadPoolExecutor;
+import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
/**
@@ -16,14 +18,21 @@
*/
public class DefaultExecutorFactory implements ExecutorFactory {
public ExecutorService getExecutor(Properties p) {
- TypedProperties tp = new TypedProperties(p);
+ TypedProperties tp = TypedProperties.toTypedProperties(p);
int maxThreads = tp.getIntProperty("maxThreads", 1);
+ int queueSize = tp.getIntProperty("queueSize", 100000);
final String threadNamePrefix = tp.getProperty("threadNamePrefix",
"Thread");
final AtomicInteger counter = new AtomicInteger(0);
- return Executors.newFixedThreadPool(maxThreads, new ThreadFactory() {
+
+ ThreadFactory tf = new ThreadFactory() {
public Thread newThread(Runnable r) {
return new Thread(threadNamePrefix + "-" +
counter.getAndIncrement());
}
- });
+ };
+
+ return new ThreadPoolExecutor(maxThreads, maxThreads,
+ 0L, TimeUnit.MILLISECONDS,
+ new LinkedBlockingQueue<Runnable>(queueSize),
+ tf);
}
}
Modified:
core/branches/flat/src/main/java/org/horizon/executors/DefaultScheduledExecutorFactory.java
===================================================================
---
core/branches/flat/src/main/java/org/horizon/executors/DefaultScheduledExecutorFactory.java 2009-01-19
11:06:16 UTC (rev 7508)
+++
core/branches/flat/src/main/java/org/horizon/executors/DefaultScheduledExecutorFactory.java 2009-01-19
13:18:35 UTC (rev 7509)
@@ -1,7 +1,5 @@
package org.horizon.executors;
-import org.horizon.util.TypedProperties;
-
import java.util.Properties;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
@@ -16,8 +14,7 @@
*/
public class DefaultScheduledExecutorFactory implements ScheduledExecutorFactory {
public ScheduledExecutorService getScheduledExecutor(Properties p) {
- TypedProperties tp = new TypedProperties(p);
- final String threadNamePrefix = tp.getProperty("threadNamePrefix",
"ScheduledThread");
+ final String threadNamePrefix = p.getProperty("threadNamePrefix",
"ScheduledThread");
final AtomicInteger counter = new AtomicInteger(0);
return Executors.newSingleThreadScheduledExecutor(new ThreadFactory() {
public Thread newThread(Runnable r) {
Show replies by date