Class AbstractLazyInitializer<T> (6.128.0)

public abstract class AbstractLazyInitializer<T>

Generic AbstractLazyInitializer for any heavy-weight object that might throw an exception during initialization. The underlying object is initialized at most once unless an exception is thrown and #shouldCacheError(Exception) returns false.

Inheritance

java.lang.Object > AbstractLazyInitializer<T>

Type Parameter

Name Description
T

Constructors

AbstractLazyInitializer()

public AbstractLazyInitializer()

Methods

get()

public T get()

Returns an initialized instance of T.

Returns
Type Description
T
Exceptions
Type Description
Exception

initialize()

protected abstract T initialize()

Initializes the actual object that should be returned. Is called once the first time an instance of T is required.

Returns
Type Description
T
Exceptions
Type Description
Exception

shouldCacheError(Exception e)

protected boolean shouldCacheError(Exception e)

Determines whether an exception thrown by #initialize() should be cached. If cached, subsequent calls to #get() will immediately rethrow the cached exception. If not cached, the exception is rethrown without marking this initializer as initialized, allowing subsequent calls to retry #initialize().

Defaults to true. Subclasses can override this method to avoid caching transient or retryable errors.

Parameter
Name Description
e Exception

the exception thrown during initialization

Returns
Type Description
boolean

true if the exception should be cached, false otherwise