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
CopyOnWriteLongArrayit 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
SafeLongArraymay 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 Lockf_lockReadRawThe raw read lock.protected com.oracle.coherence.common.util.AutoLock<LongArray<V>>f_lockWriteThe write lock, delegating to the one in the super class.protected longm_cReadsThe (dirty) total number of reads.protected longm_cReadTriggerThe read count at which to trigger a switch to a lock-free delegate.protected com.oracle.coherence.common.util.AutoLock<LongArray<V>>m_lockReadThe 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.SafeIteratorinstantiateSafeIterator(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:LongArrayMake 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:AbstractSafeLongArrayAcquire the read lock.- Specified by:
acquireReadLockin classAbstractSafeLongArray<V>- Returns:
- the lock sentry
-
acquireWriteLock
protected com.oracle.coherence.common.util.AutoLock.Sentry<LongArray<V>> acquireWriteLock()
Description copied from class:AbstractSafeLongArrayAcquire the write lock.- Specified by:
acquireWriteLockin classAbstractSafeLongArray<V>- Returns:
- the lock sentry
-
instantiateSafeIterator
protected AbstractSafeLongArray.SafeIterator instantiateSafeIterator(boolean fForward, long lIndexFrom)
Description copied from class:AbstractSafeLongArrayInstantiate a SafeIterator around the specified delegate iterator.- Overrides:
instantiateSafeIteratorin classAbstractSafeLongArray<V>- Parameters:
fForward- true if a forward iterator is to be returnedlIndexFrom- the start index- Returns:
- the safe iterator
-
-