|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.arsdigita.util.ConcurrentDict
This class allows you to intern objects in an efficient, thread-safe manner.
The classic example of interning is String.intern()
.
Interning confers two benefits:
Reduced memory footprint.
Instead of having multiple equal instances of an object scattered around in your application, you can use a single instance.
Faster equality comparison
If you know you are dealing with interned instances,
you can compare them for equality using the ==
operator
rather than the Object.equals(Object)
method.
Note: using this
class may cause a deadlock, if the methods get(Object)
and ConcurrentDict.EntrySupplier.supply(Object)
are mutually recursive. Please examine the
implementation before using this class.
Nested Class Summary | |
static interface |
ConcurrentDict.EntrySupplier
|
Constructor Summary | |
ConcurrentDict(ConcurrentDict.EntrySupplier supplier)
|
Method Summary | |
Object |
get(Object key)
Returns the object mapped to this key . |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
public ConcurrentDict(ConcurrentDict.EntrySupplier supplier)
NullPointerException
- if supplier
is nullMethod Detail |
public Object get(Object key)
key
.
If no object has been mapped to this key yet, this method will call
the ConcurrentDict.EntrySupplier.supply(Object)
method of the
supplier provided to this dictionary at construction time in ConcurrentDict(ConcurrentDict.EntrySupplier)
.
Note that the null
key is always mapped to
null
.
ConcurrentDict.EntrySupplier.supply(Object)
,
ConcurrentDict(ConcurrentDict.EntrySupplier)
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |