真正的饭馆,菜都是赁“例”,什么时候您了看见拿上来的菜单上面写着多少钱一例,那说明这嘎达较比讲究,还有——价格不菲。
1,at java.util.HashMap$HashIterator.remove(HashMap.java:858)
由于HashMap的遍历的问题:
public static HttpSession[] getHttpSessionByUser(UserSession usersession) {
HttpSession httpsession[] = null;
ArrayList<HttpSession> v = new ArrayList<HttpSession>();
Iterator<HttpSession> enume = sessionTable.keySet().iterator();
while(enume.hasNext()){
enume.remove();
/**
* 当使用 fail-fast iterator 对 Collection 或 Map 进行迭代操作过程中尝试直接修改 Collection / Map 的内容时,即使是在单线程下运行, java.util.ConcurrentModificationException 异常也将被抛出。 Iterator 是工作在一个独立的线程中,并且拥有一个 mutex 锁。 Iterator 被创建之后会建立一个指向原来对象的单链索引表,当原来的对象数量发生变化时,这个索引表的内容不会同步改变,所以当索引指针往后移动的时候就找不到要迭代的对象,所以按照 fail-fast 原则 Iterator 会马上抛出 java.util.ConcurrentModificationException 异常。
* 所以 Iterator 在工作的时候是不允许被迭代的对象被改变的。但你可以使用 Iterator 本身的方法 remove() 来删除对象, Iterator.remove() 方法会在删除当前迭代对象的同时维护索引的一致性。
*/
HttpSession session = enume.next();
UserSession user = sessionTable.get(session);
if (usersession.getUser().getUserId().equals(
user.getUser().getUserId())) {
v.add(session);
sessionTable.remove(session);
}
}
httpsession = new HttpSession[v.size()];
v.toArray(httpsession);
return httpsession;
}
如果这样写就没事了,使用的是Hashtable而非HashMap
public static HttpSession[] getHttpSessionByUser(UserSession usersession) {
HttpSession httpsession[] = null;
ArrayList<HttpSession> v = new ArrayList<HttpSession>();
Enumeration<HttpSession> enume = sessionTable.keys();
while (enume.hasMoreElements()) {
HttpSession session = enume.nextElement();
UserSession user = sessionTable.get(session);
if (usersession.getUser().getUserId().equals(
user.getUser().getUserId())) {
v.add(session);
sessionTable.remove(session);
}
}
httpsession = new HttpSession[v.size()];
v.toArray(httpsession);
return httpsession;
2,getWriter() has already been called for this response
由于同一类中PrintWriter out = response.getWriter();和ServletOutputStream ouputStream = response.getOutputStream();两个冲突。
按此阅读全文 "java.lang.IllegalStateException两例" »