标签:
Fork/Join框架的核心是由下列两个类组成的。
工作窃取算法
工作窃取(work-stealing)算法是指某个线程从其他队列里窃取任务来执行。
那么为什么需要使用工作窃取算法呢?假如我们需要做一个比较大的任务,我们可以把这个任务分割为若干互不依赖的子任务,为了减少线程间的竞争,于是把这些子任务分别放到不同的队列里,并为每个队列创建一个单独的线程来执行队列里的任务,线程和队列一一对应,比如A线程负责处理A队列里的任务。但是有的线程会先把自己队列里的任务干完,而其他线程对应的队列里还有任务等待处理。干完活的线程与其等着,不如去帮其他线程干活,于是它就去其他线程的队列里窃取一个任务来执行。而在这时它们会访问同一个队列,所以为了减少窃取任务线程和被窃取任务线程之间的竞争,通常会使用双端队列,被窃取任务线程永远从双端队列的头部拿任务执行,而窃取任务的线程永远从双端队列的尾部拿任务执行。
Fork/Join框架提供了在一个任务里执行fork()和join()操作的机制和控制任务状态的方法。通常,为了实现Fork/Join任务,需要实现一个以下两个类之一的子类。
下面我们将学习如何使用Fork/Join框架的基本元素。它包括:
本范例中即将使用的Fork/Join框架的主要特性如下:
if (problem size > default size) { tasks = divide(task); execute(tasks); } else { resolve problem using another algorithm; }
在本节,我们将实现一项更新产品价格的任务。最初的任务将负责更新列表中的所有元素。我们使用10来作为参考大小(ReferenceSize),如果一个任务需要更新大于10个元素,它会将这个列表分解成为两部分,然后分别创建两个任务用来更新各自部分的产品价格。
1. 创建一个名为Product的类,用来存储产品的名称和价格。
public class Product { private String name; private double price; public String getName() { return name; } public void setName(String name) { this.name = name; } public double getPrice() { return price; } public void setPrice(double price) { this.price = price; } }
2. 创建一个名为ProductListGenerator的类,用来生成一个随机的产品列表。
import java.util.ArrayList; import java.util.List; public class ProductListGenerator { public List<Product> generate(int size){ List<Product> ret = new ArrayList<Product>(); for(int i=0;i<size;i++){ Product product = new Product(); product.setName("Product " + i); product.setPrice(10); ret.add(product); } return ret; } }
3. 创建一个名为Task的类,并继承RecursiveAction类。
import java.util.List; import java.util.concurrent.RecursiveAction; public class Task extends RecursiveAction { private static final long serialVersionUID = 1L; private List<Product> products; private int first; private int last; private double increasement; public Task(List<Product> products, int first, int last, double increasement){ this.products = products; this.first = first; this.last = last; this.increasement = increasement; } @Override protected void compute() { if(last-first<10){ updatePrices(); }else{ int middle = (last+first)/2; System.out.printf("Task: Pending tasks: %s\n", this.getQueuedTaskCount()); Task t1 = new Task(products, first, middle+1,increasement); Task t2 = new Task(products, middle+1, last, increasement); this.invokeAll(t1, t2); } } private void updatePrices(){ for(int i=first;i<last;i++){ Product product = products.get(i); product.setPrice(product.getPrice()*(1+increasement)); } } }
4. 实现范例的主类,创建Main主类,并实现main()方法。
import java.util.List; import java.util.concurrent.ForkJoinPool; public class Main { public static void main(String[] args) { ProductListGenerator generator = new ProductListGenerator(); List<Product> products = generator.generate(10000); Task task = new Task(products, 0, products.size(), 0.20); //通过无参的类构造器创建一个ForkJoinPool ForkJoinPool pool = new ForkJoinPool(); //调用execute()方法执行任务 pool.execute(task); //显示关于线程池演变的信息 try { while(!task.isDone()){ System.out.printf("Main: Thread Count: %d\n", pool.getActiveThreadCount()); System.out.printf("Main: Thread Steal: %d\n", pool.getStealCount()); System.out.printf("Main: Parallelism: %d\n", pool.getParallelism()); Thread.sleep(5); } } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } //关闭线程池 pool.shutdown(); if(task.isCompletedNormally()){ System.out.println("Main: The process has completed normally."); } //确认是否所有的价格都已经改变 for(int i=0;i<products.size();i++){ Product product = products.get(i); if(product.getPrice()!=12) System.out.printf("Product %s: %f\n", product.getName(), product.getPrice()); } System.out.println("Main: End of the program."); } }
5. 程序运行结果如下
Task: Pending tasks: 0 Main: Thread Count: 1 Main: Thread Steal: 0 Main: Parallelism: 2 Task: Pending tasks: 1 Task: Pending tasks: 2 Task: Pending tasks: 3 Task: Pending tasks: 4 Task: Pending tasks: 5 Task: Pending tasks: 6 Task: Pending tasks: 7 Task: Pending tasks: 8 Task: Pending tasks: 9 Task: Pending tasks: 10 Task: Pending tasks: 9 Task: Pending tasks: 8 Task: Pending tasks: 9 Task: Pending tasks: 7 Task: Pending tasks: 8 Task: Pending tasks: 9 Task: Pending tasks: 7 Task: Pending tasks: 8 Task: Pending tasks: 6 Task: Pending tasks: 7 Task: Pending tasks: 8 Task: Pending tasks: 9 Task: Pending tasks: 8 Task: Pending tasks: 7 Task: Pending tasks: 8 Task: Pending tasks: 6 Task: Pending tasks: 7 Task: Pending tasks: 8 Task: Pending tasks: 6 Task: Pending tasks: 7 Task: Pending tasks: 5 Task: Pending tasks: 6 Task: Pending tasks: 7 Task: Pending tasks: 8 Task: Pending tasks: 9 Task: Pending tasks: 8 Task: Pending tasks: 7 Task: Pending tasks: 8 Task: Pending tasks: 6 Task: Pending tasks: 7 Task: Pending tasks: 8 Task: Pending tasks: 6 Task: Pending tasks: 7 Task: Pending tasks: 5 Task: Pending tasks: 6 Task: Pending tasks: 7 Task: Pending tasks: 8 Task: Pending tasks: 6 Task: Pending tasks: 7 Task: Pending tasks: 5 Task: Pending tasks: 6 Task: Pending tasks: 7 Task: Pending tasks: 5 Task: Pending tasks: 6 Task: Pending tasks: 4 Task: Pending tasks: 5 Task: Pending tasks: 6 Task: Pending tasks: 7 Task: Pending tasks: 8 Task: Pending tasks: 9 Task: Pending tasks: 8 Task: Pending tasks: 7 Task: Pending tasks: 8 Task: Pending tasks: 6 Task: Pending tasks: 7 Task: Pending tasks: 8 Task: Pending tasks: 6 Task: Pending tasks: 7 Task: Pending tasks: 5 Task: Pending tasks: 6 Task: Pending tasks: 7 Task: Pending tasks: 8 Task: Pending tasks: 7 Task: Pending tasks: 6 Task: Pending tasks: 7 Task: Pending tasks: 5 Task: Pending tasks: 6 Task: Pending tasks: 7 Task: Pending tasks: 5 Task: Pending tasks: 6 Task: Pending tasks: 4 Task: Pending tasks: 5 Task: Pending tasks: 6 Task: Pending tasks: 7 Task: Pending tasks: 8 Task: Pending tasks: 7 Task: Pending tasks: 6 Task: Pending tasks: 7 Task: Pending tasks: 5 Task: Pending tasks: 6 Task: Pending tasks: 7 Task: Pending tasks: 0 Task: Pending tasks: 1 Task: Pending tasks: 2 Task: Pending tasks: 3 Task: Pending tasks: 4 Task: Pending tasks: 5 Task: Pending tasks: 6 Task: Pending tasks: 7 Task: Pending tasks: 4 Task: Pending tasks: 5 Task: Pending tasks: 3 Task: Pending tasks: 4 Task: Pending tasks: 5 Task: Pending tasks: 6 Task: Pending tasks: 4 Task: Pending tasks: 5 Task: Pending tasks: 3 Task: Pending tasks: 4 Task: Pending tasks: 5 Task: Pending tasks: 3 Task: Pending tasks: 4 Task: Pending tasks: 2 Main: Thread Count: 2 Main: Thread Steal: 0 Main: Parallelism: 2 Task: Pending tasks: 8 Task: Pending tasks: 9 Task: Pending tasks: 8 Task: Pending tasks: 7 Task: Pending tasks: 8 Task: Pending tasks: 6 Task: Pending tasks: 7 Task: Pending tasks: 8 Task: Pending tasks: 6 Task: Pending tasks: 3 Task: Pending tasks: 4 Task: Pending tasks: 5 Task: Pending tasks: 6 Task: Pending tasks: 7 Task: Pending tasks: 8 Task: Pending tasks: 7 Task: Pending tasks: 6 Task: Pending tasks: 7 Task: Pending tasks: 5 Task: Pending tasks: 6 Task: Pending tasks: 7 Task: Pending tasks: 5 Task: Pending tasks: 6 Task: Pending tasks: 4 Task: Pending tasks: 5 Task: Pending tasks: 6 Task: Pending tasks: 7 Task: Pending tasks: 5 Task: Pending tasks: 6 Task: Pending tasks: 7 Task: Pending tasks: 8 Task: Pending tasks: 7 Task: Pending tasks: 6 Task: Pending tasks: 7 Task: Pending tasks: 5 Task: Pending tasks: 6 Task: Pending tasks: 7 Task: Pending tasks: 5 Task: Pending tasks: 6 Task: Pending tasks: 4 Task: Pending tasks: 5 Task: Pending tasks: 6 Task: Pending tasks: 7 Task: Pending tasks: 8 Task: Pending tasks: 7 Task: Pending tasks: 6 Task: Pending tasks: 7 Task: Pending tasks: 5 Task: Pending tasks: 6 Task: Pending tasks: 7 Task: Pending tasks: 5 Task: Pending tasks: 6 Task: Pending tasks: 4 Task: Pending tasks: 7 Task: Pending tasks: 5 Task: Pending tasks: 6 Task: Pending tasks: 7 Task: Pending tasks: 5 Task: Pending tasks: 6 Task: Pending tasks: 4 Task: Pending tasks: 5 Task: Pending tasks: 6 Task: Pending tasks: 4 Task: Pending tasks: 5 Task: Pending tasks: 3 Task: Pending tasks: 4 Task: Pending tasks: 6 Task: Pending tasks: 5 Task: Pending tasks: 6 Task: Pending tasks: 7 Task: Pending tasks: 8 Task: Pending tasks: 7 Task: Pending tasks: 6 Task: Pending tasks: 7 Task: Pending tasks: 5 Task: Pending tasks: 6 Task: Pending tasks: 7 Task: Pending tasks: 5 Task: Pending tasks: 6 Task: Pending tasks: 5 Task: Pending tasks: 6 Task: Pending tasks: 4 Task: Pending tasks: 5 Task: Pending tasks: 6 Task: Pending tasks: 4 Task: Pending tasks: 5 Task: Pending tasks: 3 Task: Pending tasks: 4 Task: Pending tasks: 5 Task: Pending tasks: 6 Task: Pending tasks: 7 Task: Pending tasks: 6 Task: Pending tasks: 5 Task: Pending tasks: 6 Task: Pending tasks: 4 Task: Pending tasks: 5 Task: Pending tasks: 6 Task: Pending tasks: 4 Task: Pending tasks: 5 Task: Pending tasks: 3 Task: Pending tasks: 4 Task: Pending tasks: 5 Task: Pending tasks: 6 Task: Pending tasks: 4 Task: Pending tasks: 5 Task: Pending tasks: 3 Task: Pending tasks: 4 Task: Pending tasks: 5 Task: Pending tasks: 3 Task: Pending tasks: 4 Task: Pending tasks: 2 Task: Pending tasks: 3 Task: Pending tasks: 4 Task: Pending tasks: 5 Task: Pending tasks: 6 Task: Pending tasks: 7 Task: Pending tasks: 6 Task: Pending tasks: 5 Task: Pending tasks: 6 Task: Pending tasks: 4 Task: Pending tasks: 5 Task: Pending tasks: 6 Task: Pending tasks: 4 Task: Pending tasks: 5 Task: Pending tasks: 3 Task: Pending tasks: 4 Task: Pending tasks: 5 Task: Pending tasks: 6 Task: Pending tasks: 5 Task: Pending tasks: 4 Task: Pending tasks: 5 Task: Pending tasks: 3 Task: Pending tasks: 4 Task: Pending tasks: 5 Task: Pending tasks: 3 Task: Pending tasks: 4 Task: Pending tasks: 2 Task: Pending tasks: 3 Task: Pending tasks: 4 Task: Pending tasks: 5 Task: Pending tasks: 6 Task: Pending tasks: 5 Task: Pending tasks: 4 Task: Pending tasks: 5 Task: Pending tasks: 3 Task: Pending tasks: 4 Task: Pending tasks: 5 Task: Pending tasks: 3 Task: Pending tasks: 4 Task: Pending tasks: 2 Task: Pending tasks: 3 Task: Pending tasks: 4 Task: Pending tasks: 5 Task: Pending tasks: 3 Task: Pending tasks: 4 Task: Pending tasks: 2 Main: Thread Count: 2 Task: Pending tasks: 3 Task: Pending tasks: 4 Task: Pending tasks: 2 Task: Pending tasks: 3 Task: Pending tasks: 1 Task: Pending tasks: 2 Task: Pending tasks: 3 Task: Pending tasks: 4 Task: Pending tasks: 5 Task: Pending tasks: 6 Task: Pending tasks: 7 Task: Pending tasks: 8 Task: Pending tasks: 7 Task: Pending tasks: 6 Task: Pending tasks: 7 Task: Pending tasks: 5 Task: Pending tasks: 6 Task: Pending tasks: 7 Task: Pending tasks: 5 Task: Pending tasks: 6 Task: Pending tasks: 4 Task: Pending tasks: 5 Task: Pending tasks: 6 Task: Pending tasks: 7 Task: Pending tasks: 6 Task: Pending tasks: 5 Task: Pending tasks: 6 Task: Pending tasks: 4 Task: Pending tasks: 5 Task: Pending tasks: 6 Task: Pending tasks: 4 Task: Pending tasks: 5 Task: Pending tasks: 3 Task: Pending tasks: 4 Task: Pending tasks: 5 Task: Pending tasks: 4 Task: Pending tasks: 5 Task: Pending tasks: 6 Task: Pending tasks: 7 Task: Pending tasks: 6 Task: Pending tasks: 5 Task: Pending tasks: 6 Task: Pending tasks: 4 Task: Pending tasks: 5 Task: Pending tasks: 6 Task: Pending tasks: 4 Main: Thread Steal: 0 Main: Parallelism: 2 Task: Pending tasks: 5 Task: Pending tasks: 3 Task: Pending tasks: 4 Task: Pending tasks: 5 Task: Pending tasks: 6 Task: Pending tasks: 7 Task: Pending tasks: 6 Task: Pending tasks: 5 Task: Pending tasks: 6 Task: Pending tasks: 4 Task: Pending tasks: 5 Task: Pending tasks: 6 Task: Pending tasks: 4 Task: Pending tasks: 5 Task: Pending tasks: 3 Task: Pending tasks: 4 Task: Pending tasks: 5 Task: Pending tasks: 6 Task: Pending tasks: 4 Task: Pending tasks: 5 Task: Pending tasks: 3 Task: Pending tasks: 4 Task: Pending tasks: 5 Task: Pending tasks: 3 Task: Pending tasks: 4 Task: Pending tasks: 2 Task: Pending tasks: 3 Task: Pending tasks: 4 Task: Pending tasks: 5 Task: Pending tasks: 6 Task: Pending tasks: 7 Task: Pending tasks: 6 Task: Pending tasks: 5 Task: Pending tasks: 6 Task: Pending tasks: 4 Task: Pending tasks: 5 Task: Pending tasks: 6 Task: Pending tasks: 4 Task: Pending tasks: 5 Task: Pending tasks: 3 Task: Pending tasks: 4 Task: Pending tasks: 5 Task: Pending tasks: 6 Task: Pending tasks: 5 Task: Pending tasks: 4 Task: Pending tasks: 5 Task: Pending tasks: 3 Task: Pending tasks: 4 Task: Pending tasks: 5 Task: Pending tasks: 3 Task: Pending tasks: 4 Task: Pending tasks: 2 Task: Pending tasks: 3 Task: Pending tasks: 4 Task: Pending tasks: 5 Task: Pending tasks: 6 Task: Pending tasks: 5 Task: Pending tasks: 4 Task: Pending tasks: 5 Task: Pending tasks: 3 Task: Pending tasks: 4 Task: Pending tasks: 5 Task: Pending tasks: 3 Task: Pending tasks: 4 Task: Pending tasks: 2 Task: Pending tasks: 3 Task: Pending tasks: 4 Task: Pending tasks: 5 Task: Pending tasks: 3 Task: Pending tasks: 4 Task: Pending tasks: 2 Task: Pending tasks: 3 Task: Pending tasks: 4 Task: Pending tasks: 2 Task: Pending tasks: 3 Task: Pending tasks: 1 Task: Pending tasks: 2 Task: Pending tasks: 3 Task: Pending tasks: 4 Task: Pending tasks: 5 Task: Pending tasks: 6 Task: Pending tasks: 7 Task: Pending tasks: 6 Task: Pending tasks: 5 Task: Pending tasks: 6 Task: Pending tasks: 7 Task: Pending tasks: 6 Task: Pending tasks: 5 Task: Pending tasks: 6 Task: Pending tasks: 4 Task: Pending tasks: 5 Task: Pending tasks: 6 Task: Pending tasks: 4 Task: Pending tasks: 5 Task: Pending tasks: 3 Task: Pending tasks: 4 Task: Pending tasks: 5 Main: Thread Count: 2 Main: Thread Steal: 0 Task: Pending tasks: 6 Task: Pending tasks: 4 Task: Pending tasks: 5 Task: Pending tasks: 6 Task: Pending tasks: 4 Task: Pending tasks: 5 Task: Pending tasks: 3 Task: Pending tasks: 4 Task: Pending tasks: 5 Task: Pending tasks: 6 Task: Pending tasks: 5 Task: Pending tasks: 4 Task: Pending tasks: 5 Main: Parallelism: 2 Task: Pending tasks: 3 Task: Pending tasks: 6 Task: Pending tasks: 4 Task: Pending tasks: 5 Task: Pending tasks: 3 Task: Pending tasks: 4 Task: Pending tasks: 5 Task: Pending tasks: 3 Task: Pending tasks: 4 Task: Pending tasks: 2 Task: Pending tasks: 3 Task: Pending tasks: 4 Task: Pending tasks: 5 Task: Pending tasks: 6 Task: Pending tasks: 7 Task: Pending tasks: 8 Task: Pending tasks: 7 Task: Pending tasks: 6 Task: Pending tasks: 7 Task: Pending tasks: 5 Task: Pending tasks: 6 Task: Pending tasks: 7 Task: Pending tasks: 5 Task: Pending tasks: 6 Task: Pending tasks: 4 Task: Pending tasks: 5 Task: Pending tasks: 6 Task: Pending tasks: 7 Task: Pending tasks: 6 Task: Pending tasks: 5 Task: Pending tasks: 6 Task: Pending tasks: 4 Task: Pending tasks: 5 Task: Pending tasks: 6 Task: Pending tasks: 4 Task: Pending tasks: 5 Task: Pending tasks: 3 Task: Pending tasks: 4 Task: Pending tasks: 4 Task: Pending tasks: 5 Task: Pending tasks: 3 Task: Pending tasks: 4 Task: Pending tasks: 2 Task: Pending tasks: 3 Task: Pending tasks: 4 Task: Pending tasks: 5 Task: Pending tasks: 6 Task: Pending tasks: 5 Task: Pending tasks: 4 Task: Pending tasks: 5 Task: Pending tasks: 5 Task: Pending tasks: 3 Task: Pending tasks: 4 Task: Pending tasks: 5 Task: Pending tasks: 3 Task: Pending tasks: 4 Task: Pending tasks: 2 Task: Pending tasks: 3 Task: Pending tasks: 4 Task: Pending tasks: 5 Task: Pending tasks: 3 Task: Pending tasks: 4 Task: Pending tasks: 2 Task: Pending tasks: 3 Task: Pending tasks: 4 Task: Pending tasks: 2 Task: Pending tasks: 3 Task: Pending tasks: 1 Task: Pending tasks: 2 Task: Pending tasks: 3 Task: Pending tasks: 4 Task: Pending tasks: 5 Task: Pending tasks: 6 Task: Pending tasks: 5 Task: Pending tasks: 4 Task: Pending tasks: 5 Task: Pending tasks: 3 Task: Pending tasks: 4 Task: Pending tasks: 5 Task: Pending tasks: 3 Task: Pending tasks: 4 Task: Pending tasks: 2 Task: Pending tasks: 3 Task: Pending tasks: 4 Task: Pending tasks: 5 Task: Pending tasks: 3 Task: Pending tasks: 4 Task: Pending tasks: 2 Task: Pending tasks: 3 Task: Pending tasks: 4 Task: Pending tasks: 2 Task: Pending tasks: 3 Task: Pending tasks: 1 Task: Pending tasks: 2 Task: Pending tasks: 3 Task: Pending tasks: 4 Task: Pending tasks: 5 Task: Pending tasks: 4 Task: Pending tasks: 3 Task: Pending tasks: 4 Task: Pending tasks: 2 Task: Pending tasks: 3 Task: Pending tasks: 4 Task: Pending tasks: 2 Task: Pending tasks: 3 Task: Pending tasks: 1 Task: Pending tasks: 2 Task: Pending tasks: 3 Task: Pending tasks: 4 Task: Pending tasks: 2 Task: Pending tasks: 3 Task: Pending tasks: 1 Task: Pending tasks: 2 Task: Pending tasks: 3 Task: Pending tasks: 1 Task: Pending tasks: 2 Task: Pending tasks: 0 Task: Pending tasks: 1 Task: Pending tasks: 2 Task: Pending tasks: 3 Task: Pending tasks: 4 Task: Pending tasks: 5 Task: Pending tasks: 6 Task: Pending tasks: 7 Task: Pending tasks: 8 Task: Pending tasks: 7 Task: Pending tasks: 6 Task: Pending tasks: 7 Task: Pending tasks: 5 Task: Pending tasks: 6 Task: Pending tasks: 7 Task: Pending tasks: 5 Task: Pending tasks: 6 Task: Pending tasks: 4 Task: Pending tasks: 5 Task: Pending tasks: 6 Task: Pending tasks: 7 Task: Pending tasks: 6 Task: Pending tasks: 5 Task: Pending tasks: 6 Task: Pending tasks: 4 Task: Pending tasks: 5 Task: Pending tasks: 6 Task: Pending tasks: 4 Task: Pending tasks: 5 Task: Pending tasks: 3 Task: Pending tasks: 4 Task: Pending tasks: 5 Task: Pending tasks: 6 Task: Pending tasks: 7 Task: Pending tasks: 6 Task: Pending tasks: 5 Task: Pending tasks: 6 Task: Pending tasks: 4 Task: Pending tasks: 5 Task: Pending tasks: 6 Task: Pending tasks: 4 Task: Pending tasks: 5 Task: Pending tasks: 3 Task: Pending tasks: 4 Task: Pending tasks: 5 Task: Pending tasks: 6 Task: Pending tasks: 4 Task: Pending tasks: 5 Task: Pending tasks: 3 Task: Pending tasks: 4 Task: Pending tasks: 5 Task: Pending tasks: 3 Task: Pending tasks: 4 Task: Pending tasks: 2 Task: Pending tasks: 3 Task: Pending tasks: 6 Task: Pending tasks: 4 Main: Thread Count: 2 Task: Pending tasks: 5 Task: Pending tasks: 7 Task: Pending tasks: 6 Task: Pending tasks: 7 Task: Pending tasks: 6 Task: Pending tasks: 5 Task: Pending tasks: 6 Task: Pending tasks: 4 Task: Pending tasks: 5 Task: Pending tasks: 6 Task: Pending tasks: 4 Task: Pending tasks: 5 Task: Pending tasks: 3 Task: Pending tasks: 4 Task: Pending tasks: 5 Task: Pending tasks: 6 Task: Pending tasks: 5 Task: Pending tasks: 4 Task: Pending tasks: 5 Task: Pending tasks: 3 Task: Pending tasks: 4 Task: Pending tasks: 5 Task: Pending tasks: 3 Task: Pending tasks: 4 Task: Pending tasks: 2 Task: Pending tasks: 3 Task: Pending tasks: 4 Task: Pending tasks: 5 Task: Pending tasks: 6 Task: Pending tasks: 5 Task: Pending tasks: 4 Task: Pending tasks: 5 Task: Pending tasks: 3 Task: Pending tasks: 4 Task: Pending tasks: 5 Task: Pending tasks: 3 Task: Pending tasks: 4 Main: Thread Steal: 0 Task: Pending tasks: 2 Task: Pending tasks: 3 Task: Pending tasks: 4 Task: Pending tasks: 5 Task: Pending tasks: 3 Task: Pending tasks: 4 Task: Pending tasks: 2 Task: Pending tasks: 3 Task: Pending tasks: 4 Task: Pending tasks: 2 Task: Pending tasks: 3 Task: Pending tasks: 1 Task: Pending tasks: 2 Task: Pending tasks: 3 Task: Pending tasks: 4 Task: Pending tasks: 5 Task: Pending tasks: 6 Task: Pending tasks: 7 Task: Pending tasks: 6 Task: Pending tasks: 5 Task: Pending tasks: 6 Task: Pending tasks: 4 Task: Pending tasks: 5 Task: Pending tasks: 6 Task: Pending tasks: 4 Task: Pending tasks: 5 Task: Pending tasks: 3 Task: Pending tasks: 4 Task: Pending tasks: 5 Task: Pending tasks: 6 Task: Pending tasks: 5 Task: Pending tasks: 6 Task: Pending tasks: 4 Task: Pending tasks: 5 Task: Pending tasks: 3 Task: Pending tasks: 4 Task: Pending tasks: 5 Task: Pending tasks: 3 Task: Pending tasks: 4 Task: Pending tasks: 2 Task: Pending tasks: 3 Task: Pending tasks: 4 Task: Pending tasks: 5 Task: Pending tasks: 6 Task: Pending tasks: 5 Main: Parallelism: 2 Task: Pending tasks: 5 Task: Pending tasks: 6 Task: Pending tasks: 4 Task: Pending tasks: 5 Task: Pending tasks: 6 Task: Pending tasks: 4 Task: Pending tasks: 5 Task: Pending tasks: 3 Task: Pending tasks: 4 Task: Pending tasks: 5 Task: Pending tasks: 6 Task: Pending tasks: 4 Task: Pending tasks: 5 Task: Pending tasks: 3 Task: Pending tasks: 4 Task: Pending tasks: 5 Task: Pending tasks: 3 Task: Pending tasks: 4 Task: Pending tasks: 2 Task: Pending tasks: 3 Task: Pending tasks: 4 Task: Pending tasks: 5 Task: Pending tasks: 6 Task: Pending tasks: 7 Task: Pending tasks: 6 Task: Pending tasks: 5 Task: Pending tasks: 6 Task: Pending tasks: 4 Task: Pending tasks: 5 Task: Pending tasks: 6 Task: Pending tasks: 4 Task: Pending tasks: 5 Task: Pending tasks: 3 Task: Pending tasks: 4 Task: Pending tasks: 5 Task: Pending tasks: 6 Task: Pending tasks: 5 Task: Pending tasks: 4 Task: Pending tasks: 5 Task: Pending tasks: 3 Task: Pending tasks: 4 Task: Pending tasks: 5 Task: Pending tasks: 3 Task: Pending tasks: 4 Task: Pending tasks: 2 Task: Pending tasks: 3 Task: Pending tasks: 4 Task: Pending tasks: 5 Task: Pending tasks: 6 Task: Pending tasks: 5 Task: Pending tasks: 4 Task: Pending tasks: 5 Task: Pending tasks: 3 Task: Pending tasks: 4 Task: Pending tasks: 5 Task: Pending tasks: 3 Task: Pending tasks: 4 Task: Pending tasks: 2 Task: Pending tasks: 3 Task: Pending tasks: 4 Task: Pending tasks: 5 Task: Pending tasks: 3 Task: Pending tasks: 4 Task: Pending tasks: 2 Task: Pending tasks: 3 Task: Pending tasks: 4 Task: Pending tasks: 2 Task: Pending tasks: 3 Task: Pending tasks: 1 Task: Pending tasks: 2 Task: Pending tasks: 3 Task: Pending tasks: 4 Task: Pending tasks: 5 Task: Pending tasks: 6 Task: Pending tasks: 7 Task: Pending tasks: 8 Task: Pending tasks: 7 Task: Pending tasks: 6 Task: Pending tasks: 7 Task: Pending tasks: 5 Task: Pending tasks: 6 Task: Pending tasks: 7 Task: Pending tasks: 5 Task: Pending tasks: 6 Task: Pending tasks: 4 Task: Pending tasks: 5 Task: Pending tasks: 6 Task: Pending tasks: 7 Task: Pending tasks: 6 Task: Pending tasks: 5 Task: Pending tasks: 6 Task: Pending tasks: 4 Task: Pending tasks: 5 Task: Pending tasks: 6 Task: Pending tasks: 4 Task: Pending tasks: 5 Task: Pending tasks: 3 Task: Pending tasks: 4 Task: Pending tasks: 5 Task: Pending tasks: 6 Task: Pending tasks: 7 Task: Pending tasks: 6 Task: Pending tasks: 5 Task: Pending tasks: 6 Task: Pending tasks: 4 Task: Pending tasks: 5 Task: Pending tasks: 6 Task: Pending tasks: 4 Task: Pending tasks: 5 Task: Pending tasks: 3 Task: Pending tasks: 4 Task: Pending tasks: 5 Task: Pending tasks: 6 Task: Pending tasks: 4 Task: Pending tasks: 5 Task: Pending tasks: 3 Task: Pending tasks: 4 Task: Pending tasks: 5 Task: Pending tasks: 3 Task: Pending tasks: 4 Task: Pending tasks: 2 Task: Pending tasks: 3 Task: Pending tasks: 4 Task: Pending tasks: 5 Task: Pending tasks: 6 Task: Pending tasks: 7 Task: Pending tasks: 6 Task: Pending tasks: 5 Task: Pending tasks: 6 Task: Pending tasks: 4 Task: Pending tasks: 5 Task: Pending tasks: 6 Task: Pending tasks: 4 Task: Pending tasks: 5 Task: Pending tasks: 3 Task: Pending tasks: 4 Task: Pending tasks: 5 Task: Pending tasks: 6 Task: Pending tasks: 5 Task: Pending tasks: 4 Task: Pending tasks: 5 Task: Pending tasks: 3 Task: Pending tasks: 4 Task: Pending tasks: 5 Task: Pending tasks: 3 Task: Pending tasks: 4 Task: Pending tasks: 2 Task: Pending tasks: 3 Task: Pending tasks: 4 Task: Pending tasks: 5 Task: Pending tasks: 6 Task: Pending tasks: 5 Task: Pending tasks: 4 Task: Pending tasks: 5 Task: Pending tasks: 3 Task: Pending tasks: 4 Task: Pending tasks: 5 Task: Pending tasks: 3 Task: Pending tasks: 4 Task: Pending tasks: 2 Task: Pending tasks: 3 Task: Pending tasks: 4 Task: Pending tasks: 5 Task: Pending tasks: 3 Task: Pending tasks: 4 Task: Pending tasks: 2 Task: Pending tasks: 3 Task: Pending tasks: 4 Task: Pending tasks: 2 Task: Pending tasks: 3 Task: Pending tasks: 1 Task: Pending tasks: 2 Task: Pending tasks: 3 Task: Pending tasks: 4 Task: Pending tasks: 4 Task: Pending tasks: 5 Task: Pending tasks: 6 Task: Pending tasks: 7 Task: Pending tasks: 6 Task: Pending tasks: 5 Task: Pending tasks: 6 Task: Pending tasks: 4 Task: Pending tasks: 5 Task: Pending tasks: 6 Task: Pending tasks: 4 Task: Pending tasks: 5 Task: Pending tasks: 3 Task: Pending tasks: 4 Task: Pending tasks: 5 Task: Pending tasks: 6 Task: Pending tasks: 5 Task: Pending tasks: 4 Task: Pending tasks: 5 Task: Pending tasks: 3 Task: Pending tasks: 4 Task: Pending tasks: 5 Task: Pending tasks: 3 Task: Pending tasks: 4 Task: Pending tasks: 2 Task: Pending tasks: 3 Task: Pending tasks: 4 Task: Pending tasks: 5 Task: Pending tasks: 6 Task: Pending tasks: 5 Task: Pending tasks: 4 Task: Pending tasks: 5 Task: Pending tasks: 3 Task: Pending tasks: 4 Task: Pending tasks: 5 Task: Pending tasks: 3 Task: Pending tasks: 4 Task: Pending tasks: 2 Task: Pending tasks: 3 Task: Pending tasks: 4 Task: Pending tasks: 5 Task: Pending tasks: 3 Task: Pending tasks: 4 Task: Pending tasks: 2 Task: Pending tasks: 3 Task: Pending tasks: 4 Task: Pending tasks: 2 Task: Pending tasks: 3 Task: Pending tasks: 1 Task: Pending tasks: 2 Task: Pending tasks: 3 Task: Pending tasks: 4 Task: Pending tasks: 5 Task: Pending tasks: 6 Main: Thread Count: 2 Task: Pending tasks: 5 Task: Pending tasks: 5 Task: Pending tasks: 3 Task: Pending tasks: 4 Task: Pending tasks: 5 Task: Pending tasks: 3 Task: Pending tasks: 4 Task: Pending tasks: 2 Task: Pending tasks: 3 Task: Pending tasks: 4 Task: Pending tasks: 5 Task: Pending tasks: 3 Task: Pending tasks: 4 Task: Pending tasks: 2 Task: Pending tasks: 3 Task: Pending tasks: 4 Task: Pending tasks: 2 Task: Pending tasks: 3 Task: Pending tasks: 1 Task: Pending tasks: 2 Task: Pending tasks: 3 Task: Pending tasks: 4 Task: Pending tasks: 5 Task: Pending tasks: 4 Task: Pending tasks: 5 Task: Pending tasks: 3 Task: Pending tasks: 4 Task: Pending tasks: 5 Task: Pending tasks: 3 Task: Pending tasks: 4 Task: Pending tasks: 2 Task: Pending tasks: 3 Task: Pending tasks: 4 Task: Pending tasks: 5 Task: Pending tasks: 3 Task: Pending tasks: 4 Task: Pending tasks: 2 Task: Pending tasks: 3 Task: Pending tasks: 4 Task: Pending tasks: 2 Task: Pending tasks: 3 Task: Pending tasks: 1 Task: Pending tasks: 2 Task: Pending tasks: 3 Task: Pending tasks: 4 Task: Pending tasks: 5 Task: Pending tasks: 4 Task: Pending tasks: 3 Task: Pending tasks: 4 Main: Thread Steal: 0 Main: Parallelism: 2 Task: Pending tasks: 2 Task: Pending tasks: 3 Task: Pending tasks: 4 Task: Pending tasks: 2 Task: Pending tasks: 3 Task: Pending tasks: 1 Task: Pending tasks: 2 Task: Pending tasks: 3 Task: Pending tasks: 4 Task: Pending tasks: 2 Task: Pending tasks: 3 Task: Pending tasks: 1 Task: Pending tasks: 2 Task: Pending tasks: 3 Task: Pending tasks: 1 Task: Pending tasks: 2 Task: Pending tasks: 0 Task: Pending tasks: 1 Task: Pending tasks: 2 Task: Pending tasks: 3 Task: Pending tasks: 4 Task: Pending tasks: 5 Task: Pending tasks: 6 Task: Pending tasks: 7 Task: Pending tasks: 8 Task: Pending tasks: 7 Task: Pending tasks: 6 Task: Pending tasks: 7 Task: Pending tasks: 5 Task: Pending tasks: 6 Task: Pending tasks: 7 Task: Pending tasks: 5 Task: Pending tasks: 6 Task: Pending tasks: 4 Task: Pending tasks: 5 Task: Pending tasks: 6 Task: Pending tasks: 7 Task: Pending tasks: 6 Task: Pending tasks: 5 Task: Pending tasks: 6 Task: Pending tasks: 4 Task: Pending tasks: 5 Task: Pending tasks: 6 Task: Pending tasks: 4 Task: Pending tasks: 5 Task: Pending tasks: 6 Task: Pending tasks: 5 Task: Pending tasks: 4 Task: Pending tasks: 5 Task: Pending tasks: 3 Task: Pending tasks: 4 Task: Pending tasks: 5 Task: Pending tasks: 3 Task: Pending tasks: 4 Task: Pending tasks: 3 Task: Pending tasks: 2 Task: Pending tasks: 4 Task: Pending tasks: 3 Task: Pending tasks: 4 Task: Pending tasks: 5 Task: Pending tasks: 4 Task: Pending tasks: 3 Task: Pending tasks: 4 Task: Pending tasks: 2 Task: Pending tasks: 3 Task: Pending tasks: 4 Task: Pending tasks: 5 Task: Pending tasks: 6 Task: Pending tasks: 7 Task: Pending tasks: 6 Task: Pending tasks: 5 Task: Pending tasks: 6 Task: Pending tasks: 4 Task: Pending tasks: 5 Task: Pending tasks: 6 Task: Pending tasks: 4 Task: Pending tasks: 5 Task: Pending tasks: 3 Task: Pending tasks: 4 Task: Pending tasks: 5 Task: Pending tasks: 6 Task: Pending tasks: 4 Task: Pending tasks: 5 Task: Pending tasks: 3 Task: Pending tasks: 4 Task: Pending tasks: 5 Task: Pending tasks: 3 Task: Pending tasks: 4 Task: Pending tasks: 2 Task: Pending tasks: 3 Task: Pending tasks: 4 Task: Pending tasks: 5 Task: Pending tasks: 6 Task: Pending tasks: 7 Task: Pending tasks: 6 Task: Pending tasks: 5 Task: Pending tasks: 6 Task: Pending tasks: 4 Task: Pending tasks: 5 Task: Pending tasks: 6 Task: Pending tasks: 4 Task: Pending tasks: 5 Task: Pending tasks: 3 Task: Pending tasks: 4 Task: Pending tasks: 5 Task: Pending tasks: 6 Task: Pending tasks: 5 Task: Pending tasks: 4 Task: Pending tasks: 5 Task: Pending tasks: 3 Task: Pending tasks: 4 Task: Pending tasks: 5 Task: Pending tasks: 3 Task: Pending tasks: 4 Task: Pending tasks: 2 Task: Pending tasks: 3 Task: Pending tasks: 4 Task: Pending tasks: 5 Task: Pending tasks: 6 Task: Pending tasks: 5 Task: Pending tasks: 4 Task: Pending tasks: 5 Task: Pending tasks: 3 Task: Pending tasks: 4 Task: Pending tasks: 5 Task: Pending tasks: 3 Task: Pending tasks: 4 Task: Pending tasks: 2 Task: Pending tasks: 3 Task: Pending tasks: 4 Task: Pending tasks: 5 Task: Pending tasks: 3 Task: Pending tasks: 4 Task: Pending tasks: 2 Task: Pending tasks: 3 Task: Pending tasks: 4 Task: Pending tasks: 2 Task: Pending tasks: 3 Task: Pending tasks: 1 Task: Pending tasks: 2 Task: Pending tasks: 3 Task: Pending tasks: 4 Task: Pending tasks: 5 Task: Pending tasks: 6 Task: Pending tasks: 7 Task: Pending tasks: 6 Task: Pending tasks: 5 Task: Pending tasks: 6 Task: Pending tasks: 4 Task: Pending tasks: 5 Task: Pending tasks: 6 Task: Pending tasks: 4 Task: Pending tasks: 5 Task: Pending tasks: 3 Task: Pending tasks: 4 Task: Pending tasks: 5 Task: Pending tasks: 6 Task: Pending tasks: 5 Task: Pending tasks: 4 Task: Pending tasks: 5 Task: Pending tasks: 3 Task: Pending tasks: 4 Task: Pending tasks: 5 Task: Pending tasks: 3 Task: Pending tasks: 4 Task: Pending tasks: 2 Task: Pending tasks: 3 Task: Pending tasks: 4 Task: Pending tasks: 5 Task: Pending tasks: 6 Task: Pending tasks: 5 Task: Pending tasks: 4 Task: Pending tasks: 5 Task: Pending tasks: 3 Task: Pending tasks: 4 Task: Pending tasks: 5 Task: Pending tasks: 3 Task: Pending tasks: 4 Task: Pending tasks: 2 Task: Pending tasks: 3 Task: Pending tasks: 4 Task: Pending tasks: 5 Task: Pending tasks: 3 Task: Pending tasks: 4 Task: Pending tasks: 2 Task: Pending tasks: 3 Task: Pending tasks: 4 Task: Pending tasks: 2 Task: Pending tasks: 3 Task: Pending tasks: 1 Task: Pending tasks: 2 Task: Pending tasks: 3 Task: Pending tasks: 4 Task: Pending tasks: 5 Task: Pending tasks: 6 Task: Pending tasks: 5 Task: Pending tasks: 4 Task: Pending tasks: 5 Task: Pending tasks: 3 Task: Pending tasks: 4 Task: Pending tasks: 5 Task: Pending tasks: 3 Task: Pending tasks: 4 Task: Pending tasks: 2 Task: Pending tasks: 3 Task: Pending tasks: 4 Task: Pending tasks: 5 Task: Pending tasks: 3 Task: Pending tasks: 4 Task: Pending tasks: 2 Task: Pending tasks: 3 Task: Pending tasks: 4 Task: Pending tasks: 2 Task: Pending tasks: 3 Task: Pending tasks: 1 Task: Pending tasks: 2 Task: Pending tasks: 3 Task: Pending tasks: 1 Task: Pending tasks: 2 Task: Pending tasks: 3 Task: Pending tasks: 4 Task: Pending tasks: 5 Task: Pending tasks: 4 Task: Pending tasks: 3 Task: Pending tasks: 4 Task: Pending tasks: 2 Main: Thread Count: 2 Main: Thread Steal: 0 Main: Parallelism: 2 Task: Pending tasks: 3 Task: Pending tasks: 4 Task: Pending tasks: 2 Task: Pending tasks: 3 Task: Pending tasks: 1 Task: Pending tasks: 2 Task: Pending tasks: 3 Task: Pending tasks: 4 Task: Pending tasks: 2 Task: Pending tasks: 3 Task: Pending tasks: 1 Task: Pending tasks: 2 Task: Pending tasks: 3 Task: Pending tasks: 1 Task: Pending tasks: 2 Task: Pending tasks: 0 Task: Pending tasks: 1 Task: Pending tasks: 2 Task: Pending tasks: 3 Task: Pending tasks: 4 Task: Pending tasks: 5 Task: Pending tasks: 6 Task: Pending tasks: 7 Task: Pending tasks: 6 Task: Pending tasks: 5 Task: Pending tasks: 6 Task: Pending tasks: 4 Task: Pending tasks: 5 Task: Pending tasks: 6 Task: Pending tasks: 4 Task: Pending tasks: 5 Task: Pending tasks: 3 Task: Pending tasks: 4 Task: Pending tasks: 5 Task: Pending tasks: 6 Task: Pending tasks: 5 Task: Pending tasks: 4 Task: Pending tasks: 5 Task: Pending tasks: 3 Task: Pending tasks: 4 Task: Pending tasks: 5 Task: Pending tasks: 3 Task: Pending tasks: 4 Task: Pending tasks: 2 Task: Pending tasks: 3 Task: Pending tasks: 4 Task: Pending tasks: 5 Task: Pending tasks: 6 Task: Pending tasks: 5 Task: Pending tasks: 4 Task: Pending tasks: 5 Task: Pending tasks: 3 Task: Pending tasks: 4 Task: Pending tasks: 5 Task: Pending tasks: 3 Task: Pending tasks: 4 Task: Pending tasks: 2 Task: Pending tasks: 3 Task: Pending tasks: 4 Task: Pending tasks: 5 Task: Pending tasks: 3 Task: Pending tasks: 4 Task: Pending tasks: 2 Task: Pending tasks: 3 Task: Pending tasks: 4 Task: Pending tasks: 2 Task: Pending tasks: 3 Task: Pending tasks: 1 Task: Pending tasks: 2 Task: Pending tasks: 3 Task: Pending tasks: 4 Task: Pending tasks: 5 Task: Pending tasks: 6 Task: Pending tasks: 5 Task: Pending tasks: 4 Task: Pending tasks: 5 Task: Pending tasks: 3 Task: Pending tasks: 4 Task: Pending tasks: 5 Task: Pending tasks: 3 Task: Pending tasks: 4 Task: Pending tasks: 2 Task: Pending tasks: 3 Task: Pending tasks: 4 Task: Pending tasks: 5 Task: Pending tasks: 4 Task: Pending tasks: 3 Task: Pending tasks: 4 Task: Pending tasks: 2 Task: Pending tasks: 3 Task: Pending tasks: 4 Task: Pending tasks: 2 Task: Pending tasks: 3 Task: Pending tasks: 1 Task: Pending tasks: 2 Task: Pending tasks: 3 Task: Pending tasks: 4 Task: Pending tasks: 5 Task: Pending tasks: 4 Task: Pending tasks: 3 Task: Pending tasks: 4 Task: Pending tasks: 2 Task: Pending tasks: 3 Task: Pending tasks: 4 Task: Pending tasks: 2 Task: Pending tasks: 3 Task: Pending tasks: 1 Task: Pending tasks: 2 Task: Pending tasks: 3 Task: Pending tasks: 4 Task: Pending tasks: 2 Task: Pending tasks: 3 Task: Pending tasks: 1 Task: Pending tasks: 2 Task: Pending tasks: 3 Task: Pending tasks: 1 Task: Pending tasks: 2 Task: Pending tasks: 0 Task: Pending tasks: 1 Task: Pending tasks: 2 Task: Pending tasks: 3 Task: Pending tasks: 2 Task: Pending tasks: 3 Task: Pending tasks: 4 Task: Pending tasks: 5 Task: Pending tasks: 6 Task: Pending tasks: 5 Task: Pending tasks: 4 Task: Pending tasks: 5 Task: Pending tasks: 3 Task: Pending tasks: 4 Task: Pending tasks: 5 Task: Pending tasks: 3 Task: Pending tasks: 4 Task: Pending tasks: 2 Task: Pending tasks: 3 Task: Pending tasks: 4 Task: Pending tasks: 5 Task: Pending tasks: 4 Task: Pending tasks: 3 Task: Pending tasks: 4 Task: Pending tasks: 2 Task: Pending tasks: 3 Task: Pending tasks: 4 Task: Pending tasks: 2 Task: Pending tasks: 3 Task: Pending tasks: 1 Task: Pending tasks: 2 Task: Pending tasks: 3 Task: Pending tasks: 4 Task: Pending tasks: 4 Task: Pending tasks: 5 Task: Pending tasks: 5 Task: Pending tasks: 4 Task: Pending tasks: 4 Main: Thread Count: 2 Main: Thread Steal: 0 Main: Parallelism: 2 Task: Pending tasks: 3 Task: Pending tasks: 3 Task: Pending tasks: 4 Task: Pending tasks: 4 Task: Pending tasks: 2 Task: Pending tasks: 3 Task: Pending tasks: 4 Task: Pending tasks: 2 Task: Pending tasks: 3 Task: Pending tasks: 1 Task: Pending tasks: 2 Task: Pending tasks: 3 Task: Pending tasks: 4 Task: Pending tasks: 2 Task: Pending tasks: 3 Task: Pending tasks: 1 Task: Pending tasks: 2 Task: Pending tasks: 3 Task: Pending tasks: 1 Task: Pending tasks: 2 Task: Pending tasks: 0 Task: Pending tasks: 1 Task: Pending tasks: 2 Task: Pending tasks: 3 Task: Pending tasks: 4 Task: Pending tasks: 2 Task: Pending tasks: 3 Task: Pending tasks: 4 Task: Pending tasks: 2 Task: Pending tasks: 3 Task: Pending tasks: 1 Task: Pending tasks: 2 Task: Pending tasks: 3 Task: Pending tasks: 4 Task: Pending tasks: 2 Task: Pending tasks: 3 Task: Pending tasks: 1 Task: Pending tasks: 2 Task: Pending tasks: 3 Task: Pending tasks: 1 Task: Pending tasks: 2 Task: Pending tasks: 0 Task: Pending tasks: 1 Task: Pending tasks: 2 Task: Pending tasks: 3 Task: Pending tasks: 4 Task: Pending tasks: 5 Task: Pending tasks: 6 Task: Pending tasks: 7 Task: Pending tasks: 6 Task: Pending tasks: 5 Task: Pending tasks: 6 Task: Pending tasks: 4 Task: Pending tasks: 5 Task: Pending tasks: 6 Task: Pending tasks: 4 Task: Pending tasks: 5 Task: Pending tasks: 3 Task: Pending tasks: 4 Task: Pending tasks: 5 Task: Pending tasks: 6 Task: Pending tasks: 5 Task: Pending tasks: 4 Task: Pending tasks: 5 Task: Pending tasks: 3 Task: Pending tasks: 4 Task: Pending tasks: 5 Task: Pending tasks: 3 Task: Pending tasks: 4 Task: Pending tasks: 2 Task: Pending tasks: 3 Task: Pending tasks: 4 Task: Pending tasks: 5 Task: Pending tasks: 6 Task: Pending tasks: 5 Task: Pending tasks: 4 Task: Pending tasks: 5 Task: Pending tasks: 3 Task: Pending tasks: 4 Task: Pending tasks: 5 Task: Pending tasks: 3 Task: Pending tasks: 4 Task: Pending tasks: 2 Task: Pending tasks: 3 Task: Pending tasks: 4 Task: Pending tasks: 5 Task: Pending tasks: 3 Task: Pending tasks: 4 Task: Pending tasks: 2 Task: Pending tasks: 3 Task: Pending tasks: 4 Task: Pending tasks: 2 Task: Pending tasks: 3 Task: Pending tasks: 1 Task: Pending tasks: 2 Task: Pending tasks: 3 Task: Pending tasks: 4 Task: Pending tasks: 5 Task: Pending tasks: 6 Task: Pending tasks: 5 Task: Pending tasks: 4 Task: Pending tasks: 5 Task: Pending tasks: 3 Task: Pending tasks: 4 Task: Pending tasks: 5 Task: Pending tasks: 3 Task: Pending tasks: 4 Task: Pending tasks: 2 Task: Pending tasks: 3 Task: Pending tasks: 4 Task: Pending tasks: 5 Task: Pending tasks: 4 Task: Pending tasks: 3 Task: Pending tasks: 4 Task: Pending tasks: 2 Task: Pending tasks: 3 Task: Pending tasks: 4 Task: Pending tasks: 2 Task: Pending tasks: 3 Task: Pending tasks: 1 Task: Pending tasks: 2 Task: Pending tasks: 3 Task: Pending tasks: 4 Task: Pending tasks: 5 Task: Pending tasks: 4 Task: Pending tasks: 3 Task: Pending tasks: 4 Task: Pending tasks: 2 Task: Pending tasks: 3 Task: Pending tasks: 4 Task: Pending tasks: 2 Task: Pending tasks: 3 Task: Pending tasks: 1 Task: Pending tasks: 2 Task: Pending tasks: 3 Task: Pending tasks: 4 Task: Pending tasks: 2 Task: Pending tasks: 3 Task: Pending tasks: 1 Task: Pending tasks: 2 Task: Pending tasks: 3 Task: Pending tasks: 1 Task: Pending tasks: 2 Task: Pending tasks: 0 Task: Pending tasks: 1 Task: Pending tasks: 2 Task: Pending tasks: 3 Task: Pending tasks: 4 Task: Pending tasks: 5 Task: Pending tasks: 6 Task: Pending tasks: 5 Task: Pending tasks: 4 Task: Pending tasks: 5 Task: Pending tasks: 3 Task: Pending tasks: 4 Task: Pending tasks: 5 Task: Pending tasks: 3 Task: Pending tasks: 4 Task: Pending tasks: 2 Task: Pending tasks: 3 Task: Pending tasks: 4 Task: Pending tasks: 5 Task: Pending tasks: 4 Task: Pending tasks: 3 Task: Pending tasks: 4 Task: Pending tasks: 2 Task: Pending tasks: 3 Task: Pending tasks: 4 Task: Pending tasks: 2 Task: Pending tasks: 3 Task: Pending tasks: 1 Task: Pending tasks: 2 Task: Pending tasks: 3 Task: Pending tasks: 4 Task: Pending tasks: 5 Task: Pending tasks: 4 Task: Pending tasks: 3 Task: Pending tasks: 4 Task: Pending tasks: 2 Task: Pending tasks: 3 Task: Pending tasks: 4 Task: Pending tasks: 2 Task: Pending tasks: 3 Task: Pending tasks: 1 Task: Pending tasks: 2 Task: Pending tasks: 3 Task: Pending tasks: 4 Task: Pending tasks: 2 Task: Pending tasks: 3 Task: Pending tasks: 1 Task: Pending tasks: 2 Task: Pending tasks: 3 Task: Pending tasks: 1 Task: Pending tasks: 2 Task: Pending tasks: 0 Task: Pending tasks: 1 Task: Pending tasks: 2 Task: Pending tasks: 3 Task: Pending tasks: 4 Task: Pending tasks: 5 Task: Pending tasks: 4 Task: Pending tasks: 3 Task: Pending tasks: 4 Task: Pending tasks: 2 Task: Pending tasks: 3 Task: Pending tasks: 4 Task: Pending tasks: 2 Task: Pending tasks: 3 Task: Pending tasks: 1 Task: Pending tasks: 2 Task: Pending tasks: 3 Task: Pending tasks: 4 Task: Pending tasks: 2 Task: Pending tasks: 3 Task: Pending tasks: 1 Task: Pending tasks: 2 Task: Pending tasks: 3 Task: Pending tasks: 1 Task: Pending tasks: 2 Task: Pending tasks: 0 Task: Pending tasks: 1 Task: Pending tasks: 2 Task: Pending tasks: 3 Task: Pending tasks: 4 Task: Pending tasks: 3 Task: Pending tasks: 2 Task: Pending tasks: 3 Task: Pending tasks: 1 Task: Pending tasks: 2 Task: Pending tasks: 3 Task: Pending tasks: 1 Task: Pending tasks: 2 Task: Pending tasks: 0 Task: Pending tasks: 1 Task: Pending tasks: 2 Task: Pending tasks: 3 Task: Pending tasks: 1 Task: Pending tasks: 2 Task: Pending tasks: 0 Task: Pending tasks: 1 Task: Pending tasks: 2 Task: Pending tasks: 0 Task: Pending tasks: 1 Task: Pending tasks: 0 Task: Pending tasks: 1 Task: Pending tasks: 2 Task: Pending tasks: 3 Task: Pending tasks: 4 Task: Pending tasks: 3 Task: Pending tasks: 2 Task: Pending tasks: 3 Task: Pending tasks: 1 Task: Pending tasks: 2 Task: Pending tasks: 3 Task: Pending tasks: 1 Task: Pending tasks: 2 Task: Pending tasks: 0 Task: Pending tasks: 1 Task: Pending tasks: 2 Task: Pending tasks: 3 Task: Pending tasks: 1 Task: Pending tasks: 2 Task: Pending tasks: 0 Task: Pending tasks: 1 Task: Pending tasks: 2 Task: Pending tasks: 0 Task: Pending tasks: 1 Task: Pending tasks: 0 Task: Pending tasks: 1 Task: Pending tasks: 2 Task: Pending tasks: 3 Task: Pending tasks: 1 Task: Pending tasks: 2 Task: Pending tasks: 0 Task: Pending tasks: 1 Task: Pending tasks: 2 Task: Pending tasks: 0 Task: Pending tasks: 1 Task: Pending tasks: 0 Task: Pending tasks: 1 Task: Pending tasks: 2 Task: Pending tasks: 0 Task: Pending tasks: 1 Task: Pending tasks: 0 Task: Pending tasks: 1 Task: Pending tasks: 0 Task: Pending tasks: 5 Main: Thread Count: 2 Main: Thread Steal: 7 Main: Parallelism: 2 Main: The process has completed normally. Main: End of the program.
ForkJoinPool类还提供了一下方法用于执行任务。
ForkJoinTask类也包含了在范例中使用的invokeAll()方法的其他版本,这些版本如下。
虽然ForkJoinPool类是设计用来执行ForkJoinTask对象的,但也可以直接用来执行Runnable和Callable对象。当然,也可以使用ForkJoinTask类的adapt()方法来接收一个Callable对象或者一个Runnable对象,然后将之转换为一个ForkJoinTask对象,然后再去执行。
Fork/join框架提供了执行任务并返回结果的能力。这些类型的任务都是通过RecursiveTask类来实现的。RecursiveTask类继承了ForkJoinTask类,并且实现了由执行器框架提供的Future接口。
在任务中,必须使用JavaAPI文档推荐的如下结构:
if (problem size > size) { tasks = Divide(task); execute(tasks); groupResults(); return result; } else { resolve problem; return result; }
如果任务需要解决的问题大于预先定义的大小,那么就要将这个问题拆分成多个子任务,并使用Fork/Join框架来执行这些子任务。执行完成后,原始任务获取到由所有这些子任务产生的结果,合并这些结果,返回最终的结果。当原始任务在线程池中执行结束后,将高效地获取到整个问题的最终结果。
下面我们将学习如何使用Fork/Join框架来解决这种问题,开发一个应用程序,在文档中查找一个词。我们将实现以下两种任务:
所有这些任务将返回文档或行中所出现这个词的次数。
1.
标签:
原文地址:http://www.cnblogs.com/gaopeng527/p/4910508.html