graphql.util.InterThreadMemoizedSupplier Maven / Gradle / Ivy
package graphql.util;
import graphql.Internal;
import java.util.function.Supplier;
/**
* This memoizing supplier DOES use locked double locking to set its value.
*
* @param for two
*/
@Internal
public class InterThreadMemoizedSupplier implements Supplier {
private final Supplier delegate;
private volatile boolean initialized;
private final LockKit.ReentrantLock lock = new LockKit.ReentrantLock();
private T value;
public InterThreadMemoizedSupplier(Supplier delegate) {
this.delegate = delegate;
}
@Override
public T get() {
if (!initialized) {
lock.lock();
try {
if (initialized) {
return value;
}
value = delegate.get();
initialized = true;
return value;
} finally {
lock.unlock();
}
}
return value;
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy