com.g2forge.alexandria.java.function.cache.ConcurrentFixedSupplier Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of ax-java Show documentation
Show all versions of ax-java Show documentation
Standard Java library and the basis of the ${alexandria.name} project.
package com.g2forge.alexandria.java.function.cache;
import java.util.function.Supplier;
import com.g2forge.alexandria.java.tuple.ITuple1G_;
import lombok.RequiredArgsConstructor;
@RequiredArgsConstructor
public class ConcurrentFixedSupplier implements Supplier {
protected static class Holder implements ITuple1G_ {
protected final T value;
public Holder(final T value) {
this.value = value;
}
@Override
public T get0() {
return value;
}
}
protected final Supplier extends T> supplier;
protected Holder value;
@Override
public T get() {
Holder value = this.value;
if (value == null) {
synchronized (this) {
if (this.value == null) {
this.value = new Holder(supplier.get());
}
value = this.value;
}
}
return value.get0();
}
}