Java concurrent exception in the synchronized collection
来源:互联网 发布:笑笑西卡淘宝店 编辑:程序博客网 时间:2024/05/21 07:59
I met a java concurrent exception in the synchronize collection few days ago.
Case:
In case a thread do the add/remove on this collection and another thread do the iterate
at same time. It will throw this exception.
Fix:
Way1:
Transfer it to array.
--- [instance of hashtable].values().toArray()
Due to [collection]=[hashtable].values() share the same synchronized instance key with instance of
this [hashtable], so toArray() method will be thread safe.
way2:
Synchronize [instance of hashtable] before the iterate operation.
- Java concurrent exception in the synchronized collection
- The Collection Interfaces in Java
- java.util.concurrent.locks Synchronized
- java concurrent之前戏synchronized
- Java Concurrent Modication Exception 解决
- Concurrent In Java
- Concurrent In Java
- Synchronized concurrent
- java.util.concurrent.locks.Locks和synchronized
- 使用java.util.concurrent.locks代替synchronized
- java.util.concurrent.locks与synchronized
- Garbage Collection in the Java HotSpot Virtual Machine
- Spark启动错误Exception in thread “main” java.lang.NoSuchMethodError: scala.collection.immutable.HashSet$
- Hive On Spark报错:Exception in thread "main" java.lang.NoClassDefFoundError: scala/collection/Iterable
- Set in Java Collection
- Garbage collection in Java
- collection hierarchy in java
- Garbage Collection in java
- 在RL-TCPnet下的UDP通信
- My javaeye site
- WebService中使用自定义类的解决方法
- 《软件随想录》:Joel Spolsky对计算机学生的七大建议
- ORACLE 判断表是否存在,存在则删除方法
- Java concurrent exception in the synchronized collection
- 我的编程经历
- 我对中国软件业的看法
- 十三个价值连城的成功习惯
- 嵌入式设备
- SSL - Simple of DES
- 很不错的jQuery学习资料和实例,分享给大家。
- SOCKET错误代码表
- tomcat服务器中设置.do等地址为首页的方法