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

step.core.LazyInitializer Maven / Gradle / Ivy

The newest version!
package step.core;


public abstract class LazyInitializer  {

    private static final Object NO_INIT = new Object();
    private volatile T object;

    public LazyInitializer() {
        this.object = (T) NO_INIT;
    }

    public T get()  {
        T result = this.object;
        if (result == NO_INIT) {
            synchronized(this) {
                result = this.object;
                if (result == NO_INIT) {
                    this.object = result = this.initialize();
                }
            }
        }

        return result;
    }

    protected abstract T initialize() ;

    public boolean isInitialized() {
        return this.object != NO_INIT;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy