这是FastHashMap的英文解释 A customized implementation of java.util.HashMap designed to operate in a multithreaded environment where the large majority of method calls are read-only, instead of structural changes. When operating in "fast" mode, read calls are non-synchronized and write calls perform the following steps:1.Clone the existing collection 2.Perform the modification on the clone 3.Replace the existing collection with the (modified) cloneWhen first created, objects of this class default to "slow" mode, where all accesses of any type are synchronized but no cloning takes place. This is appropriate for initially populating the collection, followed by a switch to "fast" mode (by calling setFast(true)) after initialization is complete.大哥,程序员做事情不是靠猜和想当然,真汗了。
struts好像是用到了。
从该类名称看是快速的HashMap,用其查询元素要比HashMap快很多
从类名来看,该类应该类似HashMap,但是其查询元素即get(key)要比HashMap快很多
A customized implementation of java.util.HashMap designed to operate in a multithreaded environment where the large majority of method calls are read-only, instead of structural changes. When operating in "fast" mode, read calls are non-synchronized and write calls perform the following steps:1.Clone the existing collection
2.Perform the modification on the clone
3.Replace the existing collection with the (modified) cloneWhen first created, objects of this class default to "slow" mode, where all accesses of any type are synchronized but no cloning takes place. This is appropriate for initially populating the collection, followed by a switch to "fast" mode (by calling setFast(true)) after initialization is complete.大哥,程序员做事情不是靠猜和想当然,真汗了。
但是我通篇没看到get(key)要比HashMap快很多的说法。
好好看看API说明,如果还不相信,可以写个比较程序试试
FastHashMap就是对HashMap的线程安全的包装。
import java.util.Collection;
import java.util.ConcurrentModificationException;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
这是它import的类 protected HashMap map = null;
protected boolean fast = false;
这是它的成员变量 public Object get(Object key) {
if (fast) {
return (map.get(key));
} else {
synchronized (map) {
return (map.get(key));
}
}
}
这个是它的get方法快在哪里?请楼上的指教,我没看出来。