Top Description Inners Fields Constructors Methods
com.ibm.icu.impl

public Class ICURWLock

extends Object
Class Inheritance
Imports
java.util.concurrent.locks.ReentrantReadWriteLock

A Reader/Writer lock originally written for ICU service implementation. The internal implementation was replaced with the JDK's stock read write lock (ReentrantReadWriteLock) for ICU 52.

This assumes that there will be little writing contention. It also doesn't allow active readers to acquire and release a write lock, or deal with priority inversion issues.

Access to the lock should be enclosed in a try/finally block in order to ensure that the lock is always released in case of exceptions:

try {
    lock.acquireRead();
    // use service protected by the lock
}
finally {
    lock.releaseRead();
}

The lock provides utility methods getStats and clearStats to return statistics on the use of the lock.

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static class
ICURWLock.Stats

Internal class used to gather statistics on the RWLock.

Field Summary

Modifier and TypeField and Description
private ReentrantReadWriteLock
private ICURWLock.Stats

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public void
acquireRead()

Acquire a read lock, blocking until a read lock is available.

public void
acquireWrite()

Acquire the write lock, blocking until the write lock is available.

public synchronized ICURWLock.Stats
clearStats()

Clear the stats (stop collecting stats).

public synchronized ICURWLock.Stats
getStats()

Return a snapshot of the current stats.

public void
releaseRead()

Release a read lock and return.

public void
releaseWrite()

Release the write lock and return.

public synchronized ICURWLock.Stats
resetStats()

Reset the stats.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

rwlback to summary
private ReentrantReadWriteLock rwl
statsback to summary
private ICURWLock.Stats stats

Constructor Detail

ICURWLockback to summary
public ICURWLock()

Method Detail

acquireReadback to summary
public void acquireRead()

Acquire a read lock, blocking until a read lock is available. Multiple readers can concurrently hold the read lock.

If there's a writer, or a waiting writer, increment the waiting reader count and block on this. Otherwise increment the active reader count and return. Caller must call releaseRead when done (for example, in a finally block).

acquireWriteback to summary
public void acquireWrite()

Acquire the write lock, blocking until the write lock is available. Only one writer can acquire the write lock, and when held, no readers can acquire the read lock.

If there are no readers and no waiting writers, mark as having an active writer and return. Otherwise, add a lock to the end of the waiting writer list, and block on it. Caller must call releaseWrite when done (for example, in a finally block).

clearStatsback to summary
public synchronized ICURWLock.Stats clearStats()

Clear the stats (stop collecting stats). Returns existing stats, if any.

getStatsback to summary
public synchronized ICURWLock.Stats getStats()

Return a snapshot of the current stats. This does not reset the stats.

releaseReadback to summary
public void releaseRead()

Release a read lock and return. An error will be thrown if a read lock is not currently held.

If this is the last active reader, notify the oldest waiting writer. Call when finished with work controlled by acquireRead.

releaseWriteback to summary
public void releaseWrite()

Release the write lock and return. An error will be thrown if the write lock is not currently held.

If there are waiting readers, make them all active and notify all of them. Otherwise, notify the oldest waiting writer, if any. Call when finished with work controlled by acquireWrite.

resetStatsback to summary
public synchronized ICURWLock.Stats resetStats()

Reset the stats. Returns existing stats, if any.

com.ibm.icu.impl back to summary

public final Class ICURWLock.Stats

extends Object
Class Inheritance

Internal class used to gather statistics on the RWLock.

Field Summary

Modifier and TypeField and Description
public int
_mrc

Number of times concurrent read access granted (multiple read count).

public int
_rc

Number of times read access granted (read count).

public int
_wc

Number of times write access granted (writer count).

public int
_wrc

Number of times blocked for read (waiting reader count).

public int
_wwc

Number of times blocked for write (waiting writer count).

Constructor Summary

AccessConstructor and Description
private
private
Stats(int rc, int mrc, int wrc, int wc, int wwc)

private

Method Summary

Modifier and TypeMethod and Description
public String
toString()

Overrides java.lang.Object.toString.

Return a string listing all the stats.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

_mrcback to summary
public int _mrc

Number of times concurrent read access granted (multiple read count).

_rcback to summary
public int _rc

Number of times read access granted (read count).

_wcback to summary
public int _wc

Number of times write access granted (writer count).

_wrcback to summary
public int _wrc

Number of times blocked for read (waiting reader count).

_wwcback to summary
public int _wwc

Number of times blocked for write (waiting writer count).

Constructor Detail

Statsback to summary
private Stats()
Statsback to summary
private Stats(int rc, int mrc, int wrc, int wc, int wwc)
Statsback to summary
private Stats(ICURWLock.Stats rhs)

Method Detail

toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Return a string listing all the stats.

Returns:String

Doc from java.lang.Object.toString.

a string representation of the object.

Annotations
@Override