公共类:
public static Map lhmResp = Collections.synchronizedMap(new LinkedHashMap(16,0.75f,true));
线程类1:
while (true) {
Collection mySet = Common.lhmResp.keySet();
Iterator myIteratort = mySet.iterator();
while (myIteratort.hasNext()) {
CMPPSubmit mySubmit = (CMPPSubmit) Common.lhmResp.get(myIteratort.next());
myIteratort.remove();
}
}
线程类2:
Common.lhmResp.put(key,CMPPSubmit的实例);在这种方法下,我的线程2先运行,后运行线程1,也就是不要同时运行,运行到
CMPPSubmit mySubmit = (CMPPSubmit) Common.lhmResp.get(myIteratort.next());
抛出ConcurrentModificationException异常
公共类:
public static Map lhmResp = new LinkedHashMap(16,0.75f,false);
public static Map lhmResp = Collections.synchronizedMap(new LinkedHashMap(16,0.75f,true));
线程类1:
while (true) {
Collection mySet = Common.lhmResp.keySet();
Iterator myIteratort = mySet.iterator();
while (myIteratort.hasNext()) {
CMPPSubmit mySubmit = (CMPPSubmit) Common.lhmResp.get(myIteratort.next());
myIteratort.remove();
}
}
线程类2:
synchronized(this){
Common.lhmResp.put(key,CMPPSubmit的实例);
}在这样方法下,同时运行,
运行到
CMPPSubmit mySubmit = (CMPPSubmit) Common.lhmResp.get(myIteratort.next());
抛出ConcurrentModificationException异常
public static Map lhmResp = Collections.synchronizedMap(new LinkedHashMap(16,0.75f,true));
线程类1:
while (true) {
Collection mySet = Common.lhmResp.keySet();
Iterator myIteratort = mySet.iterator();
while (myIteratort.hasNext()) {
CMPPSubmit mySubmit = (CMPPSubmit) Common.lhmResp.get(myIteratort.next());
myIteratort.remove();
}
}
线程类2:
Common.lhmResp.put(key,CMPPSubmit的实例);在这种方法下,我的线程2先运行,后运行线程1,也就是不要同时运行,运行到
CMPPSubmit mySubmit = (CMPPSubmit) Common.lhmResp.get(myIteratort.next());
抛出ConcurrentModificationException异常
公共类:
public static Map lhmResp = new LinkedHashMap(16,0.75f,false);
public static Map lhmResp = Collections.synchronizedMap(new LinkedHashMap(16,0.75f,true));
线程类1:
while (true) {
Collection mySet = Common.lhmResp.keySet();
Iterator myIteratort = mySet.iterator();
while (myIteratort.hasNext()) {
CMPPSubmit mySubmit = (CMPPSubmit) Common.lhmResp.get(myIteratort.next());
myIteratort.remove();
}
}
线程类2:
synchronized(this){
Common.lhmResp.put(key,CMPPSubmit的实例);
}在这样方法下,同时运行,
运行到
CMPPSubmit mySubmit = (CMPPSubmit) Common.lhmResp.get(myIteratort.next());
抛出ConcurrentModificationException异常
解决方案 »
- Table中某列定义为boolean, 而查询数据库得到的是0/1,如果直接add,出错!
- 在页面text中输入要查询的关键字,在检索结果中将关键字高亮显示,类似百度Google那样,怎么做啊?
- 我用javaw打开导出的jar文件怎么总是出现异常啊,格式是Executable Jar File啊
- 请问大虾们:在applet中怎样把一张图片设定为背景图片?
- 求教:如何新建一个空的文本文件?
- SUN 网上的确 JDK 1.4 有29M,有没有小点的。够用就行了!
- java数据库问题
- java的"句柄"进入函数时不是有副作用吗?可是String怎么就不呢?
- 怎样改变对象Integer的值?
- 打印嵌有applet的网页,Canon的BJC-4200没有问题,而用HP的黑白激光打印机打印,applet部分是一片黑??各位热心人请帮帮我,谢谢
- 打印的时候如何去掉四周的页边距?
- 字符串问题
public static Map lhmResp = new LinkedHashMap(16,0.75f,false);
线程类1:
while (true) {
Collection mySet = Common.lhmResp.keySet();
Iterator myIteratort = mySet.iterator();
while (myIteratort.hasNext()) {
CMPPSubmit mySubmit = (CMPPSubmit) Common.lhmResp.get(myIteratort.next());
myIteratort.remove();
}
}
线程类2:
synchronized(this){
Common.lhmResp.put(key,CMPPSubmit的实例);
}在这样方法下,同时运行,
运行到
CMPPSubmit mySubmit = (CMPPSubmit) Common.lhmResp.get(myIteratort.next());
抛出ConcurrentModificationException异常