Package org.apache.fop.fo.properties
Class PropertyCache<T>
java.lang.Object
org.apache.fop.fo.properties.PropertyCache<T>
- Type Parameters:
T
- The type of values that are cached
Thread-safe cache that minimizes the memory requirements by fetching an instance from the cache
that is equal to the given one. Internally the instances are stored in WeakReferences in order to
be reclaimed when they are no longer referenced.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final Lock
Lock to prevent concurrent cleanup of the map.private final AtomicInteger
private static final org.apache.commons.logging.Log
private final ConcurrentMap<Integer,
WeakReference<T>> The underlying map that stores WeakReferences to the cached entries.private final AtomicInteger
Counts the number of entries put in the map in order to periodically check and remove the entries whose referents have been reclaimed.private final boolean
Determines if the cache is used based on the value of the system property org.apache.fop.fo.properties.use-cache -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate void
private void
private boolean
Returns a cached version of the given object.
-
Field Details
-
LOG
private static final org.apache.commons.logging.Log LOG -
useCache
private final boolean useCacheDetermines if the cache is used based on the value of the system property org.apache.fop.fo.properties.use-cache -
map
The underlying map that stores WeakReferences to the cached entries. The map keys are the hashCode of the cached entries. The map values are a WeakRefence to the cached entries. When two cached entries have the same hash code, the last one is kept but this should be an exception case (otherwise the hashCode() method of T needs to be fixed). -
putCounter
Counts the number of entries put in the map in order to periodically check and remove the entries whose referents have been reclaimed. -
cleanupLock
Lock to prevent concurrent cleanup of the map. -
hashCodeCollisionCounter
-
-
Constructor Details
-
PropertyCache
public PropertyCache()Creates a new cache. The "org.apache.fop.fo.properties.use-cache" system property is used to determine whether properties should actually be cached or not. If not, then thefetch(Object)
method will simply return its argument. To enable the cache, set this property to "true" (case insensitive).
-
-
Method Details
-
fetch
Returns a cached version of the given object. If the object is not yet in the cache, it will be added and then returned.- Parameters:
obj
- an object- Returns:
- a cached version of the object
-
attemptCleanup
private void attemptCleanup() -
cleanReclaimedMapEntries
private void cleanReclaimedMapEntries() -
eq
-