# Class ParallelRunner

java.lang.Object
org.apfloat.internal.ParallelRunner

public class ParallelRunner extends Object
Class for running `ParallelRunnable` objects in parallel using multiple threads.

The ParallelRunner assumes that the current `ApfloatContext` returns an `ExecutorService` that is limited to a number of threads that is one less than the number of processors. This way, when also the current thread runs batches from the `ParallelRunnable`, CPU utilization should be maximized but only so that no more threads are actively executing than the number of processors.

Since:
  1.1
Version:
  1.16.0
Author:
  Mikko Tommila

- ## Method Summary

  Modifier and Type
  Method
  Description
  `static void`
  `runParallel(ParallelRunnable parallelRunnable)`
  Run a ParallelRunnable object in parallel using multiple threads.
  `static void`
  `wait(Future<?> future)`
  While waiting for a `Future` to be completed, steal a minimal amount of work from any running task and run it.

  ### Methods inherited from class Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Method Details

  - ### runParallel

    public static void runParallel(ParallelRunnable parallelRunnable) throws ApfloatRuntimeException
    Run a ParallelRunnable object in parallel using multiple threads. The method assumes that the `ExecutorService` returned from `ApfloatContext.getExecutorService()` is limited to using one thread less than the number of processors. This maximizes CPU usage, When the `ParallelRunnable` is also run from the current thread.
    Parameters:
      `parallelRunnable` - The ParallelRunnable to be run.
    Throws:
      `ApfloatRuntimeException`

  - ### wait

    public static void wait(Future<?> future)
    While waiting for a `Future` to be completed, steal a minimal amount of work from any running task and run it.
    Parameters:
      `future` - The Future to wait for.