????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();
    }