public static class CPU.JVMExecutor
extends java.lang.Object
CPU.JVMExecutor
offers a similar functionality as the parallel stream API,
however it differs in that the CPU.JVMExecutor
is processing CPU.RangeWorkload
lambdas
instead of simply exposing a single index or concrete elements for a given workload size.
This means that a CPU.RangeWorkload
lambda will be called with the work range of a single worker thread
processing its current workload.
This range is dependent on the number of available threads as well as the size of the workload.
If the workload is very small, then the current main thread will process the entire workload range
whereas the underlying ThreadPoolExecutor
will not be used to avoid unnecessary overhead.Constructor and Description |
---|
JVMExecutor() |
Modifier and Type | Method and Description |
---|---|
int |
getActiveThreadCount()
Returns the approximate number of threads that are actively
executing tasks.
|
long |
getCompletedTaskCount()
Returns the approximate total number of tasks that have
completed execution.
|
int |
getCorePoolSize()
Returns the core number of threads.
|
void |
sequential(int workloadSize,
CPU.RangeWorkload workload)
This method will simply execute the provided
CPU.RangeWorkload lambda sequentially
with 0 as the start index and workloadSize as the exclusive range. |
void |
threaded(int numberOfWorkloads,
CPU.IndexedWorkload workload)
Executes the provided workload lambda across multiple threads
where the provided worker lambda will receive the index/id of the current worker.
|
void |
threaded(int workloadSize,
CPU.RangeWorkload workload)
This method slices the provided workload size into multiple ranges which can be executed in parallel.
|
void |
threaded(int first,
int limit,
CPU.RangeWorkload rangeWorkload)
Takes the provided range and divides it into multithreaded workloads.
|
public int getActiveThreadCount()
public int getCorePoolSize()
public long getCompletedTaskCount()
public void threaded(int workloadSize, CPU.RangeWorkload workload)
workloadSize
- The total workload size which ought to be split into multiple ranges.workload
- The range lambda which ought to be executed across multiple threads.public void threaded(int numberOfWorkloads, CPU.IndexedWorkload workload)
numberOfWorkloads
- The total number of workloads to be executed.workload
- The workload lambda to be executed.public void sequential(int workloadSize, CPU.RangeWorkload workload)
CPU.RangeWorkload
lambda sequentially
with 0 as the start index and workloadSize
as the exclusive range. workloadSize
- The workload size which will be passed to the provided CPU.RangeWorkload
as second argument.workload
- The CPU.RangeWorkload
which will be executed sequentially.public void threaded(int first, int limit, CPU.RangeWorkload rangeWorkload)
first
- The start index of the threaded workload range.limit
- The limit for the workload range, which is exclusive.rangeWorkload
- A workload lambda which will be called by different threads with different sub-ranges.