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

commons.box.app.DataInit Maven / Gradle / Ivy

The newest version!
package commons.box.app;

/**
 * 允许初始化的实例,可以根据运行状态重新初始化
 */
public abstract class DataInit {
    private volatile boolean initialized = false;

    /**
     * 初始化实例,可以重复调用,仅在需要初始化时才会真正执行初始化过程
     */
    public void init() {
        if (!this.initialized) {
            synchronized (this) {
                if (!this.initialized) {
                    internalInit();
                    this.initialized = true;
                }
            }
        }
    }

    /**
     * 重新初始化
     */
    public void reset() {
        if (this.initialized) {
            synchronized (this) {
                this.initialized = false;
            }
        }
    }

    /**
     * 内部初始化
     */
    protected abstract void internalInit();
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy