net.sf.javagimmicks.lang.AbstractCreateOnDemandObjectContainer Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of gimmicks Show documentation
Show all versions of gimmicks Show documentation
Utility classes, APIs and tools for Java
package net.sf.javagimmicks.lang;
abstract class AbstractCreateOnDemandObjectContainer implements ObjectContainer
{
private final Factory _factory;
protected AbstractCreateOnDemandObjectContainer(final Factory factory)
{
_factory = factory;
}
@Override
public final E get()
{
E instance = getInstance();
if (instance != null)
{
return instance;
}
synchronized (this)
{
instance = getInstance();
if (instance == null)
{
instance = _factory.create();
setInstance(instance);
}
}
return instance;
}
abstract protected E getInstance();
abstract protected void setInstance(E instance);
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy