public class ConcurrencyReducer<T> extends Object
ConcurrencyReducer
is used to queue tasks which will be
executed in a manner reducing the number of concurrent tasks.
Note: This is a port of ConcurrencyLimiter from futures-extra for use with CompletionStagesModifier and Type | Class and Description |
---|---|
static class |
ConcurrencyReducer.CapacityReachedException |
Modifier and Type | Method and Description |
---|---|
CompletableFuture<T> |
add(Callable<? extends CompletionStage<T>> callable)
the callable function will run as soon as the currently active set of futures is less than the
maxConcurrency limit.
|
static <T> ConcurrencyReducer<T> |
create(int maxConcurrency,
int maxQueueSize) |
int |
numActive() |
int |
numQueued() |
int |
remainingActiveCapacity() |
int |
remainingQueueCapacity() |
public static <T> ConcurrencyReducer<T> create(int maxConcurrency, int maxQueueSize)
maxConcurrency
- maximum number of futures in progress,maxQueueSize
- maximum number of jobs in queue. This is a soft bound and may be
temporarily exceeded if add() is called concurrently.public CompletableFuture<T> add(Callable<? extends CompletionStage<T>> callable)
callable
- - a function that creates a future.ConcurrencyReducer.CapacityReachedException
if the soft queue
size limit is exceeded.public int numQueued()
public int numActive()
public int remainingQueueCapacity()
public int remainingActiveCapacity()
Copyright © 2018 Spotify AB. All rights reserved.