cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ga...@apache.org
Subject svn commit: r1497643 - /cxf/web/src/main/java/org/apache/cxf/cwiki/SiteExporter.java
Date Fri, 28 Jun 2013 04:16:30 GMT
Author: gawor
Date: Fri Jun 28 04:16:29 2013
New Revision: 1497643

URL: http://svn.apache.org/r1497643
Log:
add option to control the number of render threads as too many threads can overwhelm the server

Modified:
    cxf/web/src/main/java/org/apache/cxf/cwiki/SiteExporter.java

Modified: cxf/web/src/main/java/org/apache/cxf/cwiki/SiteExporter.java
URL: http://svn.apache.org/viewvc/cxf/web/src/main/java/org/apache/cxf/cwiki/SiteExporter.java?rev=1497643&r1=1497642&r2=1497643&view=diff
==============================================================================
--- cxf/web/src/main/java/org/apache/cxf/cwiki/SiteExporter.java (original)
+++ cxf/web/src/main/java/org/apache/cxf/cwiki/SiteExporter.java Fri Jun 28 04:16:29 2013
@@ -47,6 +47,8 @@ import java.util.Set;
 import java.util.concurrent.ConcurrentHashMap;
 import java.util.concurrent.ConcurrentLinkedQueue;
 import java.util.concurrent.CopyOnWriteArraySet;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
 import java.util.concurrent.Future;
 import java.util.concurrent.atomic.AtomicInteger;
 
@@ -1099,6 +1101,7 @@ public class SiteExporter implements Run
         ListIterator<String> it = Arrays.asList(args).listIterator();
         List<String> files = new ArrayList<String>();
         boolean forceAll = false;
+        int maxThreads = -1;
         while (it.hasNext()) {
             String s = it.next();
             if ("-debug".equals(s)) {
@@ -1115,6 +1118,8 @@ public class SiteExporter implements Run
                 svn = true;
             } else if ("-commit".equals(s)) {
                 commit = true;
+            } else if ("-maxThreads".equals(s)) {
+                maxThreads = Integer.parseInt(it.next());
             } else if (s != null && s.length() > 0) {
                 files.add(s);
             }
@@ -1136,14 +1141,17 @@ public class SiteExporter implements Run
         if (!modified.isEmpty()) {
             setSiteExporters(exporters);
 
-            List<Thread> threads = new ArrayList<Thread>(modified.size());
+            if (maxThreads <= 0) {
+                maxThreads = modified.size();
+            }
+
+            ExecutorService executor = Executors.newFixedThreadPool(maxThreads);
+            List<Future<?>> futures = new ArrayList<Future<?>>(modified.size());
             for (SiteExporter exporter : modified) {
-                Thread t = new Thread(exporter);
-                threads.add(t);
-                t.start();
+                futures.add(executor.submit(exporter));
             }
-            for (Thread t : threads) {
-                t.join();
+            for (Future<?> t : futures) {
+                t.get();
             }
         }
                 



Mime
View raw message