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

com.slimgears.util.stream.ThreadLazy Maven / Gradle / Ivy

There is a newer version: 0.7.58
Show newest version
package com.slimgears.util.stream;

import java.util.function.Supplier;

public class ThreadLazy extends ThreadLocal implements Supplier {
    private final Supplier supplier;

    private ThreadLazy(Supplier supplier) {
        this.supplier = supplier;
    }

    @Override
    public T get() {
        T instance = super.get();
        if (instance == null) {
            instance = supplier.get();
            set(instance);
        }
        return instance;
    }

    public static  ThreadLazy of(Supplier supplier) {
        return new ThreadLazy<>(supplier);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy