Package org.alfresco.util
Class ReadWriteLockExecuter<T>
- java.lang.Object
-
- org.alfresco.util.ReadWriteLockExecuter<T>
-
public abstract class ReadWriteLockExecuter<T> extends java.lang.Object
Utility object that wraps read and write methods within the context of aReentrantReadWriteLock
. The callback's methods are best-suited to fetching values from a cache or protecting members that need lazy initialization.Client code should construct an instance of this class for each resource (or set of resources) that need to be protected.
- Since:
- 3.4
- Author:
- Derek Hulley
-
-
Constructor Summary
Constructors Constructor Description ReadWriteLockExecuter()
Default constructor
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description T
execute()
protected abstract T
getWithReadLock()
Execute the read-only part of the work.protected abstract T
getWithWriteLock()
Execute the write part of the work.
-
-
-
Method Detail
-
getWithReadLock
protected abstract T getWithReadLock() throws java.lang.Throwable
Execute the read-only part of the work.- Returns:
- Returns a value of interest or null if
the
getWithWriteLock()
method must be called - Throws:
java.lang.Throwable
- all checked exceptions are wrapped in a RuntimeException
-
getWithWriteLock
protected abstract T getWithWriteLock() throws java.lang.Throwable
Execute the write part of the work.NOTE: It is important to perform a double-check on the resource before assuming it is not null; there is a window between the
getWithReadLock()
and thegetWithWriteLock()
during which another thread may have populated the resource of interest.- Returns:
- Returns the value of interest of null
- Throws:
java.lang.Throwable
- all checked exceptions are wrapped in a RuntimeException
-
execute
public T execute()
-
-