java.lang.Object
com.pivovarit.collectors.ParallelCollectors.Batching
- Enclosing class:
ParallelCollectors
A subset of collectors which perform operations in batches and not separately (one object in a thread pool's worker queue represents a batch of operations to be performed by a single thread)
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic <T,
R> Collector <T, ?, CompletableFuture<Stream<R>>> A convenienceCollector
used for executing parallel computations on a customExecutor
and returning them asCompletableFuture
containing aStream
of these elements.static <T,
R, RR> Collector <T, ?, CompletableFuture<RR>> A convenienceCollector
used for executing parallel computations on a customExecutor
and returning them as aCompletableFuture
containing a result of the application of the user-providedCollector
.parallelToOrderedStream
(Function<T, R> mapper, Executor executor, int parallelism) parallelToStream
(Function<T, R> mapper, Executor executor, int parallelism)
-
Constructor Details
-
Batching
private Batching()
-
-
Method Details
-
parallel
public static <T,R, Collector<T,RR> ?, parallelCompletableFuture<RR>> (Function<T, R> mapper, Collector<R, ?, RR> collector, Executor executor, int parallelism) A convenienceCollector
used for executing parallel computations on a customExecutor
and returning them as aCompletableFuture
containing a result of the application of the user-providedCollector
.
Example:CompletableFuture<List<String>> result = Stream.of(1, 2, 3) .collect(parallel(i -> foo(i), toList(), executor, 2));
- Type Parameters:
T
- the type of the collected elementsR
- the result returned bymapper
RR
- the reduction resultcollector
- Parameters:
mapper
- a transformation to be performed in parallelcollector
- theCollector
describing the reductionexecutor
- theExecutor
to use for asynchronous executionparallelism
- the max parallelism level- Returns:
- a
Collector
which collects all processed elements into a user-provided mutableCollection
in parallel - Since:
- 2.1.0
-
parallel
public static <T,R> Collector<T,?, parallelCompletableFuture<Stream<R>>> (Function<T, R> mapper, Executor executor, int parallelism) A convenienceCollector
used for executing parallel computations on a customExecutor
and returning them asCompletableFuture
containing aStream
of these elements.
The collector maintains the order of processedStream
. Instances should not be reused.
Example:CompletableFuture<Stream<String>> result = Stream.of(1, 2, 3) .collect(parallel(i -> foo(), executor, 2));
- Type Parameters:
T
- the type of the collected elementsR
- the result returned bymapper
- Parameters:
mapper
- a transformation to be performed in parallelexecutor
- theExecutor
to use for asynchronous executionparallelism
- the max parallelism level- Returns:
- a
Collector
which collects all processed elements into aStream
in parallel - Since:
- 2.1.0
-
parallelToStream
public static <T,R> Collector<T,?, parallelToStreamStream<R>> (Function<T, R> mapper, Executor executor, int parallelism) A convenienceCollector
used for executing parallel computations on a customExecutor
and returning aStream
instance returning results as they arrive.For the parallelism of 1, the stream is executed by the calling thread.
Example:Stream.of(1, 2, 3) .collect(parallelToStream(i -> foo(), executor, 2)) .forEach(System.out::println);
- Type Parameters:
T
- the type of the collected elementsR
- the result returned bymapper
- Parameters:
mapper
- a transformation to be performed in parallelexecutor
- theExecutor
to use for asynchronous executionparallelism
- the max parallelism level- Returns:
- a
Collector
which collects all processed elements into aStream
in parallel - Since:
- 2.1.0
-
parallelToOrderedStream
public static <T,R> Collector<T,?, parallelToOrderedStreamStream<R>> (Function<T, R> mapper, Executor executor, int parallelism) A convenienceCollector
used for executing parallel computations on a customExecutor
and returning aStream
instance returning results as they arrive while maintaining the initial order.For the parallelism of 1, the stream is executed by the calling thread.
Example:Stream.of(1, 2, 3) .collect(parallelToOrderedStream(i -> foo(), executor, 2)) .forEach(System.out::println);
- Type Parameters:
T
- the type of the collected elementsR
- the result returned bymapper
- Parameters:
mapper
- a transformation to be performed in parallelexecutor
- theExecutor
to use for asynchronous executionparallelism
- the max parallelism level- Returns:
- a
Collector
which collects all processed elements into aStream
in parallel - Since:
- 2.1.0
-