public abstract class ReadWriteLockExecuter<T> extends Object
ReentrantReadWriteLock
. 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.
Constructor and Description |
---|
ReadWriteLockExecuter()
Default constructor
|
Modifier and Type | Method and 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.
|
protected abstract T getWithReadLock() throws Throwable
getWithWriteLock()
method must be
calledThrowable
- all checked exceptions are wrapped in a RuntimeExceptionprotected abstract T getWithWriteLock() throws Throwable
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 the getWithWriteLock()
during which another thread may have populated
the resource of interest.
Throwable
- all checked exceptions are wrapped in a RuntimeExceptionpublic T execute()
Copyright © 2005–2020 Alfresco Software. All rights reserved.