Class WeakConcurrentSet<V>
java.lang.Object
com.pnfsoftware.jeb.util.concurrent.WeakConcurrentSet<V>
- Type Parameters:
V- value type
A thread-safe set with weak values. Entries are based on a key's system hash code and keys are
considered equal only by reference equality.
This class does not implement the Set interface because this implementation is
incompatible with the set contract. While iterating over a set's entries, any value that has not
passed iteration is referenced non-weakly.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumDetermines the cleaning format. -
Constructor Summary
ConstructorsConstructorDescriptionCreate a weak-value concurrent set. -
Method Summary
Modifier and TypeMethodDescriptionbooleanintReturns the approximate size of this set where the returned number is at least as big as the actual number of entries.voidclear()Clears the set.booleanvoidCleans all unused references.iterator()Iterate over live values.booleanvoidrun()Run the underlying cleaner loop until interrupted.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface java.lang.Iterable
forEach, spliterator
-
Constructor Details
-
WeakConcurrentSet
Create a weak-value concurrent set.- Parameters:
cleaner- cleanup strategy for stale entries
-
-
Method Details
-
add
- Parameters:
value- The value to add to the set.- Returns:
trueif the value was added to the set and was not contained before.
-
contains
- Parameters:
value- The value to check if it is contained in the set.- Returns:
trueif the set contains the value.
-
remove
- Parameters:
value- The value to remove from the set.- Returns:
trueif the value is contained in the set.
-
clear
public void clear()Clears the set. -
approximateSize
public int approximateSize()Returns the approximate size of this set where the returned number is at least as big as the actual number of entries.- Returns:
- the approximate size of this set
-
run
public void run()Run the underlying cleaner loop until interrupted. -
expungeStaleEntries
public void expungeStaleEntries()Cleans all unused references. -
getCleanerThread
- Returns:
- The cleaner thread or
nullif no such thread was set.
-
iterator
Iterate over live values.
-