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>
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:
-
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
Modifier and TypeFieldDescriptionprotected final Lock
The raw read lock.The write lock, delegating to the one in the super class.protected long
The (dirty) total number of reads.protected long
The read count at which to trigger a switch to a lock-free delegate.The mutable read lock.Fields inherited from class com.tangosol.util.AbstractSafeLongArray
NO_VALUE
-
Constructor Summary
ConstructorDescriptionConstruct a ReadHeavyLongArray.ReadHeavyLongArray
(LongArray<V> delegate) Construct a ReadHeavyLongArray around the specified delegate. -
Method Summary
Modifier and TypeMethodDescriptionAcquire the read lock.Acquire the write lock.clone()
Make a clone of the LongArray.protected AbstractSafeLongArray<V>.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 Details
-
f_lockWrite
The write lock, delegating to the one in the super class. -
f_lockReadRaw
The raw read lock. -
m_lockRead
The mutable read lock. -
m_cReads
protected long m_cReadsThe (dirty) total number of reads. -
m_cReadTrigger
protected long m_cReadTriggerThe read count at which to trigger a switch to a lock-free delegate.
-
-
Constructor Details
-
ReadHeavyLongArray
public ReadHeavyLongArray()Construct a ReadHeavyLongArray. -
ReadHeavyLongArray
Construct a ReadHeavyLongArray around the specified delegate.- Parameters:
delegate
- the delegate long array, it is not safe to externally access this array
-
-
Method Details
-
clone
Description copied from interface:LongArray
Make a clone of the LongArray. The element values are not deep-cloned. -
acquireReadLock
Description copied from class:AbstractSafeLongArray
Acquire the read lock.- Specified by:
acquireReadLock
in classAbstractSafeLongArray<V>
- Returns:
- the lock sentry
-
acquireWriteLock
Description copied from class:AbstractSafeLongArray
Acquire the write lock.- Specified by:
acquireWriteLock
in classAbstractSafeLongArray<V>
- Returns:
- the lock sentry
-
instantiateSafeIterator
protected AbstractSafeLongArray<V>.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
-