Class ThreadsafeLazyLoadedReference<V>
java.lang.Object
java.lang.ref.Reference<V>
java.lang.ref.WeakReference<V>
io.atlassian.util.concurrent.LazyReference<V>
com.atlassian.jira.util.concurrent.ThreadsafeLazyLoadedReference<V>
- All Implemented Interfaces:
Supplier<V>
@Deprecated
public abstract class ThreadsafeLazyLoadedReference<V>
extends io.atlassian.util.concurrent.LazyReference<V>
Deprecated.
Thread-safe lock-less (see note) reference that is not constructed until required. This class is used to maintain a
reference to an object that is expensive to create and must be constructed once and once only. Therefore this
reference behaves as though the
final keyword has been used (you cannot reset it once it has been
constructed).
When using this class you need to implement the LazyReference.create() method to return the object this reference will
hold.
For instance:
final ThreadsafeLazyLoadedReference ref = new ThreadsafeLazyLoadedReference()
{
protected Object create() throws Exception
{
// Do some useful object construction here
return new MyObject();
}
};
Then call to get a reference to the object:
MyObject myLazyLoadedObject = (MyObject) ref.get()
Interruption policy is that if you want to be cancellable while waiting for another thread to create the value,
instead of calling LazyReference.get() call LazyReference.getInterruptibly(). If your LazyReference.create() method throws an
InterruptedException however, it will be the causal exception inside the runtime
exception that LazyReference.get() or LazyReference.getInterruptibly() throws and your LazyReference.create()
will not be called again.
-
Nested Class Summary
Nested classes/interfaces inherited from class io.atlassian.util.concurrent.LazyReference
io.atlassian.util.concurrent.LazyReference.InitializationException -
Constructor Summary
Constructors -
Method Summary
Methods inherited from class io.atlassian.util.concurrent.LazyReference
cancel, create, get, getInterruptibly, isInitializedMethods inherited from class java.lang.ref.Reference
clear, clone, enqueue, isEnqueued, reachabilityFence, refersTo
-
Constructor Details
-
ThreadsafeLazyLoadedReference
public ThreadsafeLazyLoadedReference()Deprecated.
-
LazyReferenceinstead.