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

gw.util.LazyInit Maven / Gradle / Ivy

There is a newer version: 1.18.2
Show newest version
/*
 * Copyright 2014 Guidewire Software, Inc.
 */

package gw.util;

import gw.lang.reflect.TypeSystem;

public abstract class LazyInit {

  private boolean _initializing = false;
  private boolean _initialized = false;

  protected final void maybeInit() {
    TypeSystem.lock();
    try {
      if ( _initialized ) {
        return;
      }
      if ( _initializing ) {
        throw new IllegalStateException( "Recursive Initialization" );
      }
      _initializing = true;
      try {
        initialize();
        _initialized = true;
      }
      finally {
        _initializing = false;
      }
    }
    finally {
      TypeSystem.unlock();
    }
  }

  protected abstract void initialize();

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy