@Internal public class MultipleFuturesAvailabilityHelper extends Object
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).
构造器和说明 |
---|
MultipleFuturesAvailabilityHelper(int size) |
限定符和类型 | 方法和说明 |
---|---|
void |
anyOf(int idx,
CompletableFuture<?> availabilityFuture)
Combine
availabilityFuture using anyOf logic with other previously registered
futures. |
CompletableFuture<?> |
getAvailableFuture() |
void |
resetToUnAvailable() |
public CompletableFuture<?> getAvailableFuture()
public void resetToUnAvailable()
public void anyOf(int idx, CompletableFuture<?> availabilityFuture)
availabilityFuture
using anyOf logic with other previously registered
futures.Copyright © 2014–2022 The Apache Software Foundation. All rights reserved.