Class ConcurrentReferenceHashMap.Segment
java.lang.Object
java.util.concurrent.locks.ReentrantLock
nl.basjes.parse.useragent.utils.springframework.util.ConcurrentReferenceHashMap.Segment
- All Implemented Interfaces:
Serializable
,Lock
- Enclosing class:
- ConcurrentReferenceHashMap<K,
V>
A single segment used to divide the map to allow better concurrent performance.
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
clear()
Clear all items from this segment.<T> T
doTask
(int hash, Object key, ConcurrentReferenceHashMap<K, V>.nl.basjes.parse.useragent.utils.springframework.util.ConcurrentReferenceHashMap.Task<T> task) Apply an update operation to this segment.int
getCount()
Return the total number of references in this segment.getReference
(Object key, int hash, ConcurrentReferenceHashMap.Restructure restructure) protected void
restructureIfNecessary
(boolean allowResize) Restructure the underlying data structure when it becomes necessary.Methods inherited from class java.util.concurrent.locks.ReentrantLock
getHoldCount, getOwner, getQueuedThreads, getQueueLength, getWaitingThreads, getWaitQueueLength, hasQueuedThread, hasQueuedThreads, hasWaiters, isFair, isHeldByCurrentThread, isLocked, lock, lockInterruptibly, newCondition, toString, tryLock, tryLock, unlock
-
Constructor Details
-
Segment
public Segment(int initialSize, int resizeThreshold)
-
-
Method Details
-
getReference
@Nullable public ConcurrentReferenceHashMap.Reference<K,V> getReference(@Nullable Object key, int hash, ConcurrentReferenceHashMap.Restructure restructure) -
doTask
@Nullable public <T> T doTask(int hash, @Nullable Object key, ConcurrentReferenceHashMap<K, V>.nl.basjes.parse.useragent.utils.springframework.util.ConcurrentReferenceHashMap.Task<T> task) Apply an update operation to this segment. The segment will be locked during the update.- Parameters:
hash
- the hash of the keykey
- the keytask
- the update operation- Returns:
- the result of the operation
-
clear
public void clear()Clear all items from this segment. -
restructureIfNecessary
protected void restructureIfNecessary(boolean allowResize) Restructure the underlying data structure when it becomes necessary. This method can increase the size of the references table as well as purge any references that have been garbage collected.- Parameters:
allowResize
- if resizing is permitted
-
getCount
public int getCount()Return the total number of references in this segment.
-