graphql.util.InterThreadMemoizedSupplier Maven / Gradle / Ivy
package graphql.util;
import graphql.Internal;
import java.util.function.Supplier;
/**
* This memoizing supplier DOES use synchronised double locking to set its value.
*
* @param for two
*/
@Internal
public class InterThreadMemoizedSupplier implements Supplier {
private final Supplier delegate;
private volatile boolean initialized;
private T value;
public InterThreadMemoizedSupplier(Supplier delegate) {
this.delegate = delegate;
}
@Override
public T get() {
if (!initialized) {
synchronized (this) {
if (initialized) {
return value;
}
value = delegate.get();
initialized = true;
return value;
}
}
return value;
}
}