??????????Java??????
???????????? ???????[ 2013/2/27 9:59:38 ] ????????
????Java???????У????????? Collection ????е???????????????????????????? Collection?????????Щ????£??????????????????????????????????Щ?????????????? JRE ??????????? collection ??????????????????????иò???????????????????? ?????????????????????????????????e?????????????????????????????????
???????????????????ArrayList???????????????????ArrayList????е???????????????ConcurrentModificationException??
????????????????
final List<String> tickets = new ArrayList<String>();
for (int i = 0; i < 100000; i++) {
tickets.add("ticket NO??" + i);
}
System.out.println("start1...");
for (int i = 0; i < 10; i++) {
Thread salethread = new Thread() {
public void run() {
while (tickets.size() > 0) {
tickets.remove(0);
System.out.println(Thread.currentThread().getId()+"Remove 0");
}
}
};
salethread.start();
}
System.out.println("start2...");
new Thread() {
public void run() {
for (String s : tickets) {
System.out.println(s);
}
}
}.start();
???????????????к???????????????
????java.util.ConcurrentModificationException
????at java.util.ArrayList$Itr.checkForComodification(Unknown Source)
????at java.util.ArrayList$Itr.next(Unknown Source)
????at mytest.mytestpkg.Tj$2.run(Tj.java:138)
????Vector????????????????ArrayList???Vector???????????
????????????????????????ArrayList????Vector?????????Collection???????????fail-fast??????????????????????????????????????????Υ??????漲?????????
????--------------------------------------------------------------------------------
??????????Vector?????ArrayList??????????????????????????????????ArrayList???????????Vector?????????????????????????Ч????
??????????????????????10??????ü?????????????????????????????????????????????????????????????????????????
????????????????
final List<String> tickets = new ArrayList<String>();
for (int i = 0; i < 100000; i++) {
tickets.add("ticket NO??" + i);
}
System.out.println("start1...");
for (int i = 0; i < 10; i++) {
Thread salethread = new Thread() {
public void run() {
while (true) {
if(tickets.size()>0)
System.out.println(Thread.currentThread().getId()+ tickets.remove(0));
else
break;
}
}
};
salethread.start();
}
??????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11