Package org.apfloat.internal
Class ParallelRunner
- java.lang.Object
-
- org.apfloat.internal.ParallelRunner
-
public class ParallelRunner extends java.lang.ObjectClass for runningParallelRunnableobjects in parallel using multiple threads.The ParallelRunner assumes that the current
ApfloatContextreturns anExecutorServicethat 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 theParallelRunnable, 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.14.0
-
-
Field Summary
Fields Modifier and Type Field Description private static java.util.Queue<ParallelRunnable>tasks
-
Constructor Summary
Constructors Modifier Constructor Description privateParallelRunner()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static voidrunParallel(ParallelRunnable parallelRunnable)Run a ParallelRunnable object in parallel using multiple threads.private static voidrunTasks(java.lang.Runnable runnable)static voidwait(java.util.concurrent.Future<?> future)While waiting for aFutureto be completed, steal a minimal amount of work from any running task and run it.
-
-
-
Field Detail
-
tasks
private static java.util.Queue<ParallelRunnable> tasks
-
-
Method Detail
-
runParallel
public static void runParallel(ParallelRunnable parallelRunnable) throws ApfloatRuntimeException
Run a ParallelRunnable object in parallel using multiple threads. The method assumes that theExecutorServicereturned fromApfloatContext.getExecutorService()is limited to using one thread less than the number of processors. This maximizes CPU usage, When theParallelRunnableis also run from the current thread.- Parameters:
parallelRunnable- The ParallelRunnable to be run.- Throws:
ApfloatRuntimeException
-
wait
public static void wait(java.util.concurrent.Future<?> future)
While waiting for aFutureto be completed, steal a minimal amount of work from any running task and run it.- Parameters:
future- The Future to wait for.
-
runTasks
private static void runTasks(java.lang.Runnable runnable)
-
-