一個朋友給我發的,問我線程安全麼?
public class Cache {
private Map cache = new HashMap() ;
public Object get(String key) {
return cache.get(key);
}
public void reload(){
Map tempCache = loadFromDB();
cache = tempCache; // safe ?
}
}