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

com.wizzardo.tools.misc.SoftThreadLocal Maven / Gradle / Ivy

There is a newer version: 0.23
Show newest version
package com.wizzardo.tools.misc;

import java.lang.ref.SoftReference;

/**
 * @author: wizzardo
 * Date: 8/8/14
 */
public class SoftThreadLocal extends ThreadLocal> {

    @Override
    protected SoftReference initialValue() {
        return new SoftReference(init());
    }

    protected T init() {
        return null;
    }

    public T getValue() {
        SoftReference reference = get();
        T t = reference.get();
        if (t == null) {
            t = init();
            setValue(t);
        }
        return t;
    }

    public void setValue(T t) {
        set(new SoftReference(t));
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy