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

com.g2forge.alexandria.java.function.cache.ConcurrentFixedSupplier Maven / Gradle / Ivy

There is a newer version: 0.0.18
Show newest version
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 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();
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy