Package com.tangosol.util
Class ReadHeavyLongArray<V>
- java.lang.Object
-
- com.tangosol.util.AbstractSafeLongArray<V>
-
- com.tangosol.util.ReadHeavyLongArray<V>
-
- All Implemented Interfaces:
LongArray<V>
,Serializable
,Cloneable
,Iterable<V>
public class ReadHeavyLongArray<V> extends AbstractSafeLongArray<V>
A thread-safe LongArray implementation for read heavy workloads but which is also efficient with frequent and/or bursty writes.This implementation provides thread-safety via a combination of locking and copy-on-write. Unlike the
CopyOnWriteLongArray
it will in general allow for many mutations within a single copy. When the read to write ratio is high enough (think thousands of reads per write) the read locks will be elided allowing for maximum performance.For workloads with a read to write ratio close to 1:1 or where writes are more common then reads the
SafeLongArray
may be more appropriate.- Author:
- mf 2014.10.02
- See Also:
- Serialized Form
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class com.tangosol.util.AbstractSafeLongArray
AbstractSafeLongArray.SafeIterator
-
Nested classes/interfaces inherited from interface com.tangosol.util.LongArray
LongArray.Iterator<V>
-
-
Field Summary
Fields Modifier and Type Field Description protected Lock
f_lockReadRaw
The raw read lock.protected com.oracle.coherence.common.util.AutoLock<LongArray<V>>
f_lockWrite
The write lock, delegating to the one in the super class.protected long
m_cReads
The (dirty) total number of reads.protected long
m_cReadTrigger
The read count at which to trigger a switch to a lock-free delegate.protected com.oracle.coherence.common.util.AutoLock<LongArray<V>>
m_lockRead
The mutable read lock.-
Fields inherited from class com.tangosol.util.AbstractSafeLongArray
NO_VALUE
-
-
Constructor Summary
Constructors Constructor Description ReadHeavyLongArray()
Construct a ReadHeavyLongArray.ReadHeavyLongArray(LongArray<V> delegate)
Construct a ReadHeavyLongArray around the specified delegate.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected com.oracle.coherence.common.util.AutoLock.Sentry<LongArray<V>>
acquireReadLock()
Acquire the read lock.protected com.oracle.coherence.common.util.AutoLock.Sentry<LongArray<V>>
acquireWriteLock()
Acquire the write lock.ReadHeavyLongArray<V>
clone()
Make a clone of the LongArray.protected AbstractSafeLongArray.SafeIterator
instantiateSafeIterator(boolean fForward, long lIndexFrom)
Instantiate a SafeIterator around the specified delegate iterator.-
Methods inherited from class com.tangosol.util.AbstractSafeLongArray
add, ceiling, ceilingIndex, clear, contains, exists, floor, floorIndex, get, getFirstIndex, getLastIndex, getSize, indexOf, indexOf, isEmpty, iterator, iterator, lastIndexOf, lastIndexOf, remove, remove, reverseIterator, reverseIterator, set, toString
-
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
-
-
-
Field Detail
-
f_lockWrite
protected final com.oracle.coherence.common.util.AutoLock<LongArray<V>> f_lockWrite
The write lock, delegating to the one in the super class.
-
f_lockReadRaw
protected final Lock f_lockReadRaw
The raw read lock.
-
m_lockRead
protected volatile com.oracle.coherence.common.util.AutoLock<LongArray<V>> m_lockRead
The mutable read lock.
-
m_cReads
protected long m_cReads
The (dirty) total number of reads.
-
m_cReadTrigger
protected long m_cReadTrigger
The read count at which to trigger a switch to a lock-free delegate.
-
-
Method Detail
-
clone
public ReadHeavyLongArray<V> clone()
Description copied from interface:LongArray
Make a clone of the LongArray. The element values are not deep-cloned.
-
acquireReadLock
protected com.oracle.coherence.common.util.AutoLock.Sentry<LongArray<V>> acquireReadLock()
Description copied from class:AbstractSafeLongArray
Acquire the read lock.- Specified by:
acquireReadLock
in classAbstractSafeLongArray<V>
- Returns:
- the lock sentry
-
acquireWriteLock
protected com.oracle.coherence.common.util.AutoLock.Sentry<LongArray<V>> acquireWriteLock()
Description copied from class:AbstractSafeLongArray
Acquire the write lock.- Specified by:
acquireWriteLock
in classAbstractSafeLongArray<V>
- Returns:
- the lock sentry
-
instantiateSafeIterator
protected AbstractSafeLongArray.SafeIterator instantiateSafeIterator(boolean fForward, long lIndexFrom)
Description copied from class:AbstractSafeLongArray
Instantiate a SafeIterator around the specified delegate iterator.- Overrides:
instantiateSafeIterator
in classAbstractSafeLongArray<V>
- Parameters:
fForward
- true if a forward iterator is to be returnedlIndexFrom
- the start index- Returns:
- the safe iterator
-
-