具体代码:
private static final ThreadLocal USER_CONN = new ThreadLocal() {
protected Object initialValue() {
return new HashSet();
}
}; public static void freeAll() {
Set set = (Set) USER_CONN.get();
for (Iterator it = set.iterator(); it.hasNext();) {
freeConnection((Connection) it.next());
}
set.clear();
}
在freeConnection((Connection) it.next());时会出现NoSuchElement
public static void freeAll() {
Set set = (Set) USER_CONN.get();
for (Iterator it = set.iterator(); it.hasNext();) {
                           Connection conn = (Connection) it.next();
freeConnection(conn);
}
set.clear();
}
就没问题