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)
-
Method Summary
Modifier and TypeMethodDescriptionstatic <T,R> Collector <T, ?, CompletableFuture<Stream<R>>> A convenienceCollectorused for executing parallel computations on a customExecutorand returning them asCompletableFuturecontaining aStreamof these elements.static <T,R, RR> Collector <T, ?, CompletableFuture<RR>> A convenienceCollectorused for executing parallel computations on a customExecutorand returning them as aCompletableFuturecontaining 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)
-
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 convenienceCollectorused for executing parallel computations on a customExecutorand returning them as aCompletableFuturecontaining 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 bymapperRR- the reduction resultcollector- Parameters:
mapper- a transformation to be performed in parallelcollector- theCollectordescribing the reductionexecutor- theExecutorto use for asynchronous executionparallelism- the max parallelism level- Returns:
- a
Collectorwhich collects all processed elements into a user-provided mutableCollectionin parallel - Since:
- 2.1.0
-
parallel
public static <T,R> Collector<T,?, parallelCompletableFuture<Stream<R>>> (Function<T, R> mapper, Executor executor, int parallelism) A convenienceCollectorused for executing parallel computations on a customExecutorand returning them asCompletableFuturecontaining aStreamof 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- theExecutorto use for asynchronous executionparallelism- the max parallelism level- Returns:
- a
Collectorwhich collects all processed elements into aStreamin parallel - Since:
- 2.1.0
-
parallelToStream
public static <T,R> Collector<T,?, parallelToStreamStream<R>> (Function<T, R> mapper, Executor executor, int parallelism) A convenienceCollectorused for executing parallel computations on a customExecutorand returning aStreaminstance 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- theExecutorto use for asynchronous executionparallelism- the max parallelism level- Returns:
- a
Collectorwhich collects all processed elements into aStreamin parallel - Since:
- 2.1.0
-
parallelToOrderedStream
public static <T,R> Collector<T,?, parallelToOrderedStreamStream<R>> (Function<T, R> mapper, Executor executor, int parallelism) A convenienceCollectorused for executing parallel computations on a customExecutorand returning aStreaminstance 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- theExecutorto use for asynchronous executionparallelism- the max parallelism level- Returns:
- a
Collectorwhich collects all processed elements into aStreamin parallel - Since:
- 2.1.0
-