Преглед на файлове

#68 CQuery: ForkJoinPool.commonPool

Ranides Atterwim преди 4 години
родител
ревизия
61659ae9e6
променени са 1 файла, в които са добавени 13 реда и са изтрити 2 реда
  1. 13 2
      assira.core/src/main/java/net/ranides/assira/collection/query/support/BaseSpliteratorParalell.java

+ 13 - 2
assira.core/src/main/java/net/ranides/assira/collection/query/support/BaseSpliteratorParalell.java

@@ -21,6 +21,17 @@ import java.util.stream.StreamSupport;
 @UtilityClass
 public class BaseSpliteratorParalell {
 
+    /**
+     * This number tells how many additional splits are introduced into every working task.
+     * Value 3 means, that every fragment will be roughly 8 times shorter than "theoretical exact".
+     */
+    private static final int SPLIT_FACTOR = 3;
+
+    /**
+     * This number is the minimum size of working task. Tasks with smaller size won't be split.
+     */
+    private static final int SPLIT_BOUND = 3;
+
     public static <T> void forEach(Spliterator<T> that, Consumer<? super T> consumer) {
         StreamSupport.stream(that, true).forEach(consumer);
     }
@@ -164,8 +175,8 @@ public class BaseSpliteratorParalell {
         int splits = MathUtils.log2floor(executor.getParallelism());
 
         long n = that.getExactSizeIfKnown();
-        for(int i = 0; i<3; i++, splits++) {
-            if(n / (1L << splits) <= 3) {
+        for(int i = 0; i< SPLIT_FACTOR; i++, splits++) {
+            if(n / (1L << splits) <= SPLIT_BOUND) {
                 break;
             }
         }