/** * Returns the runtime object associated with the current Java application. * Most of the methods of class <code>Runtime</code> are instance * methods and must be invoked with respect to the current runtime object. * * @return the <code>Runtime</code> object associated with the current * Java application. */ publicstatic Runtime getRuntime() { return currentRuntime; }
/** Don't let anyone else instantiate this class */ privateRuntime() {}
/** * The array of bins. Lazily initialized upon first insertion. * Size is always a power of two. Accessed directly by iterators. * * hash表,在第一次put数据的时候才初始化,他的大小总是2的倍数。 */ transientvolatile Node<K,V>[] table;
/** * 用来存储一个键值对 * * Key-value entry. This class is never exported out as a * user-mutable Map.Entry (i.e., one supporting setValue; see * MapEntry below), but can be used for read-only traversals used * in bulk tasks. Subclasses of Node with a negative hash field * are special, and contain null keys and values (but are never * exported). Otherwise, keys and vals are never null. */ staticclassNode<K,V> implementsMap.Entry<K,V> { finalint hash; final K key; volatile V val; volatile Node<K,V> next; }
/** * Maps the specified key to the specified value in this table. * Neither the key nor the value can be null. * * <p>The value can be retrieved by calling the {@code get} method * with a key that is equal to the original key. * * @param key key with which the specified value is to be associated * @param value value to be associated with the specified key * @return the previous value associated with {@code key}, or * {@code null} if there was no mapping for {@code key} * @throws NullPointerException if the specified key or value is null */ public V put(K key, V value) { return putVal(key, value, false); }
/** Implementation for put and putIfAbsent */ final V putVal(K key, V value, boolean onlyIfAbsent) { if (key == null || value == null) thrownewNullPointerException(); // 计算key的hash值 inthash= spread(key.hashCode()); intbinCount=0; for (Node<K,V>[] tab = table;;) { Node<K,V> f; int n, i, fh; // 如果table是空,初始化之 if (tab == null || (n = tab.length) == 0) tab = initTable(); // 省略... } // 省略... }