Class MultipleFuturesAvailabilityHelper
notifyCompletion() is allowed to be executed
from an outside of the task thread.
It solves a problem of a potential memory leak as described in FLINK-25728. In short we have
to ensure, that if there is one input (future) that rarely (or never) completes, that such future
would not prevent previously returned combined futures (like CompletableFuture.anyOf(CompletableFuture[]) from being garbage collected. Additionally, we
don't want to accumulate more and more completion stages on such rarely completed future, so we
are registering CompletableFuture.thenRun(Runnable) only if it has not already been done.
Note resetToUnAvailable() doesn't de register previously registered futures. If
future was registered in the past, but for whatever reason now it is not, such future can still
complete the newly created future.
It might be no longer needed after upgrading to JDK9 (https://bugs.openjdk.java.net/browse/JDK-8160402).
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidanyOf(int idx, CompletableFuture<?> availabilityFuture) CombineavailabilityFutureusing anyOf logic with other previously registered futures.void
-
Constructor Details
-
MultipleFuturesAvailabilityHelper
public MultipleFuturesAvailabilityHelper(int size)
-
-
Method Details
-
getAvailableFuture
- Returns:
- combined future using anyOf logic
-
resetToUnAvailable
public void resetToUnAvailable() -
anyOf
CombineavailabilityFutureusing anyOf logic with other previously registered futures.
-