|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.sleepycat.je.latch.SharedLatch
public class SharedLatch
Simple thread-based non-transactional reader-writer/shared-exclusive latch. Latches provide simple exclusive or shared transient locks on objects. Latches are expected to be held for short, defined periods of time. No deadlock detection is provided so it is the caller's responsibility to sequence latch acquisition in an ordered fashion to avoid deadlocks. Nested latches for a single thread are supported, but upgrading a shared latch to an exclusive latch is not. This implementation is based on the section Reader-Writer Locks in the book Java Threads by Scott Oaks, 2nd Edition, Chapter 8.
Constructor Summary | |
---|---|
SharedLatch(Object subject,
String name,
EnvironmentImpl env)
Create a latch with a backpointer to its subject (the object that is protected by the latch along with a name (both for debugging purposes). |
Method Summary | |
---|---|
void |
acquireExclusive()
Acquire a latch for exclusive/write access. |
void |
acquireShared()
Acquire a latch for shared/read access. |
static void |
clearNotes()
|
static int |
countLatchesHeld()
Only call under the assert system. |
static void |
dumpLatchesHeld()
|
(package private) LatchStats |
getLatchStats()
Used for debugging latches. |
Object |
getSubject()
|
boolean |
isOwner()
Return true if the current thread holds this latch. |
static String |
latchesHeldToString()
|
(package private) int |
nWaiters()
Return the number of threads waiting. |
Thread |
owner()
Used only for unit tests. |
void |
release()
Release an exclusive or shared latch. |
void |
setName(String name)
Set the latch name, used for latches in objects instantiated from the log. |
String |
toString()
Formats a latch owner and waiters. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
public SharedLatch(Object subject, String name, EnvironmentImpl env)
Method Detail |
---|
public void setName(String name)
public Object getSubject()
public void acquireExclusive() throws DatabaseException
LatchException
- if the latch is already held by the current
thread for shared access.
RunRecoveryException
- if an InterruptedException exception
occurs.
DatabaseException
public void acquireShared() throws DatabaseException
RunRecoveryException
- if an InterruptedException exception
occurs.
DatabaseException
public void release() throws LatchNotHeldException
LatchNotHeldException
- if the latch is not currently held.public boolean isOwner()
public Thread owner()
int nWaiters()
LatchStats getLatchStats()
public String toString()
toString
in class Object
public static int countLatchesHeld()
public static void dumpLatchesHeld()
public static String latchesHeldToString()
public static void clearNotes()
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |