com.sleepycat.je.latch
Class Latch

java.lang.Object
  extended by com.sleepycat.je.latch.Latch
Direct Known Subclasses:
TimingLatch

public class Latch
extends Object


Constructor Summary
Latch(String name)
           
 
Method Summary
 void acquire()
          Acquire a latch for exclusive/write access.
 boolean acquireNoWait()
          Acquire a latch for exclusive/write access, but do not block if it's not available.
 void clear()
           
 StatGroup getLatchStats()
           
 String getName()
          Used by com.sleepycat.je.utilint.TimingLatch.
 boolean isOwner()
          Return true if the current thread holds this latch.
 int nWaiters()
          Return the number of threads waiting.
 Thread owner()
          Used only for unit tests.
 void release()
          Release the latch.
 void releaseIfOwner()
          Release the 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

Latch

public Latch(String name)
Method Detail

setName

public void setName(String name)
Set the latch name, used for latches in objects instantiated from the log.


getName

public String getName()
Used by com.sleepycat.je.utilint.TimingLatch.


acquire

public void acquire()
Acquire a latch for exclusive/write access.

Wait for the latch if some other thread is holding it. If there are threads waiting for access, they will be granted the latch on a FIFO basis. When the method returns, the latch is held for exclusive access.

Throws:
EnvironmentFailureException - if the latch is already held by the calling thread.

acquireNoWait

public boolean acquireNoWait()
Acquire a latch for exclusive/write access, but do not block if it's not available.

Returns:
true if the latch was acquired, false if it is not available.
Throws:
EnvironmentFailureException - if the latch is already held by the calling thread.

releaseIfOwner

public void releaseIfOwner()
Release the latch. If there are other thread(s) waiting for the latch, one is woken up and granted the latch. If the latch was not owned by the caller, just return;


release

public void release()
Release the latch. If there are other thread(s) waiting for the latch, they are woken up and granted the latch.

Throws:
EnvironmentFailureException - if the latch is not currently held.

isOwner

public boolean isOwner()
Return true if the current thread holds this latch.

Returns:
true if we hold this latch. False otherwise.

owner

public Thread owner()
Used only for unit tests.

Returns:
the thread that currently holds the latch for exclusive access.

nWaiters

public int nWaiters()
Return the number of threads waiting.

Returns:
the number of threads waiting for the latch.

getLatchStats

public StatGroup getLatchStats()
Returns:
a LatchStats object with information about this latch.

clear

public void clear()

toString

public String toString()
Formats a latch owner and waiters.

Overrides:
toString in class Object


Copyright (c) 2004-2010 Oracle. All rights reserved.