All Downloads are FREE. Search and download functionalities are using the official Maven repository.

graphql.util.InterThreadMemoizedSupplier Maven / Gradle / Ivy

There is a newer version: 230521-nf-execution
Show newest version
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;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy