a) 集合的选择
b) String、StringBuffer、StringBuilder
String、StringBuffer、StringBuilder都是采用char数组实现的
StringBuffer、StringBuilder默认初始化16个
扩容int newCapacity = (value.length + 1) * 2;
c) Vector、Hashtable、Stack(Collections. synchronizedList)
d) 减少I/O访问(缓存)
e) 读写分开(分盘)
f) 线程同步块
g) 单例模式实现缓存(Map)
//伪代码(采用单例模式实现缓存)
class Cache {
private Map map;
private static Cache instance = new Cache();
private Cache() {}
public static Cache getInstance() {
return instance;
}
public synchronized getObject(String className) {
if (map.containts(className)) {
return map.get(className);
}else {
Object instance = Class.forName(className).newInstance();
map.put(className, instance);
}
}
}