|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object java.lang.ThreadLocal.ThreadLocalMap
ThreadLocalMap is a customized hash map suitable only for maintaining thread local values. No operations are exported outside of the ThreadLocal class. The class is package private to allow declaration of fields in class Thread. To help deal with very large and long-lived usages, the hash table entries use WeakReferences for keys. However, since reference queues are not used, stale entries are guaranteed to be removed only when the table starts running out of space.
Nested Class Summary | |
private static class |
ThreadLocal.ThreadLocalMap.Entry
The entries in this hash map extend WeakReference, using its main ref field as the key (which is always a ThreadLocal object). |
Field Summary | |
private static int |
INITIAL_CAPACITY
The initial capacity -- MUST be a power of two. |
private int |
size
The number of entries in the table. |
private ThreadLocal.ThreadLocalMap.Entry[] |
table
The table, resized as necessary. |
private int |
threshold
The next size value at which to resize. |
Constructor Summary | |
private |
ThreadLocal.ThreadLocalMap(ThreadLocal.ThreadLocalMap parentMap)
Construct a new map including all Inheritable ThreadLocals from given parent map. |
(package private) |
ThreadLocal.ThreadLocalMap(ThreadLocal firstKey,
Object firstValue)
Construct a new map initially containing (firstKey, firstValue). |
Method Summary | |
private void |
expungeStaleEntries()
Expunge all stale entries in the table. |
private void |
expungeStaleEntry(int staleSlot)
Expunge a stale entry by rehashing any possibly colliding entries lying between staleSlot and the next null slot. |
private Object |
get(ThreadLocal key)
Get the value associated with key with code h. |
private Object |
getAfterMiss(ThreadLocal key,
int i,
ThreadLocal.ThreadLocalMap.Entry e)
Version of get method for use when key is not found in its direct hash slot. |
private static int |
nextIndex(int i,
int len)
Increment i modulo len. |
private static int |
prevIndex(int i,
int len)
Decrement i modulo len. |
private void |
rehash()
Re-pack and/or re-size the table. |
private Object |
replaceStaleEntry(ThreadLocal key,
Object value,
int staleSlot,
boolean actAsGet)
Replace a stale entry encountered during a get or set operation with an entry for the specified key. |
private void |
resize()
Double the capacity of the table. |
private void |
set(ThreadLocal key,
Object value)
Set the value associated with key. |
private void |
setThreshold(int len)
Set the resize threshold to maintain at worst a 2/3 load factor. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
private static final int INITIAL_CAPACITY
private ThreadLocal.ThreadLocalMap.Entry[] table
private int size
private int threshold
Constructor Detail |
ThreadLocal.ThreadLocalMap(ThreadLocal firstKey, Object firstValue)
private ThreadLocal.ThreadLocalMap(ThreadLocal.ThreadLocalMap parentMap)
parentMap
- the map associated with parent thread.Method Detail |
private void setThreshold(int len)
private static int nextIndex(int i, int len)
private static int prevIndex(int i, int len)
private Object get(ThreadLocal key)
key
- the thread local object
private Object getAfterMiss(ThreadLocal key, int i, ThreadLocal.ThreadLocalMap.Entry e)
key
- the thread local objecti
- the table index for key's hash codee
- the entry at table[i];
private void set(ThreadLocal key, Object value)
key
- the thread local objectvalue
- the value to be setprivate Object replaceStaleEntry(ThreadLocal key, Object value, int staleSlot, boolean actAsGet)
key
- the keyvalue
- the value to be associated with key; meaningful only
if actAsGet is false.staleSlot
- index of the first stale entry encountered while
searching for key.actAsGet
- true if this method should act as a get; false
it should act as a set.
private void expungeStaleEntry(int staleSlot)
staleSlot
- index of slot known to have null keyprivate void rehash()
private void resize()
private void expungeStaleEntries()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |