具体代码:
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();
}
就没问题
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();
}
就没问题
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货