1

java.util.ConcurrentModificationException在单击按钮时多次执行以下代码时得到

for(Iterator <PrintWriter> it=TABhs.iterator();it.hasNext();)
                    { 
                        PrintWriter ot=it.next();
                        ot.println("tableupdate#"+tables+"#"+kotno+"#processing");
                        ot.flush();
                        JOptionPane.showMessageDialog(rootPane, "<html><body>Table Kot Status Changed to <b>Processing</b></body></html>");
                    }

谁能告诉我一些解决方案

这里 TABhs 是带有 PrintWriter 泛型的 HashSet

HashSet <PrintWriter> TABhs=new HashSet<PrintWriter>();

按钮点击动作如下图所示

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                         
      String stat=status_combo.getSelectedItem().toString();
      String tables=tableno_combo.getSelectedItem().toString();
      String kotno=kotno_combo.getSelectedItem().toString();

      if(stat.equals("Processing"))
      {
            try {
                String quer="UPDATE table_orders SET status='"+stat.toLowerCase()+"' WHERE tableno='"+tables+"' AND kotno='"+kotno+"'";  
                int restatus=dbGetDet.insertDetails(quer);
                if(restatus>0){
                filtercomboBox();
                fillTable();
                for(Iterator <PrintWriter> it=TABhs.iterator();it.hasNext();)
                { 
                    PrintWriter ot=it.next();
                    ot.println("tableupdate#"+tables+"#"+kotno+"#processing");
                    ot.flush();
                    JOptionPane.showMessageDialog(rootPane, "<html><body>Table Kot Status Changed to <b>Processing</b></body></html>");
                }



                    System.out.println("TABhs--------------------->"+TABhs.size());
                }
            } catch (Exception ex) {
                Logger.getLogger(MYClientclass.class.getName()).log(Level.SEVERE, null, ex);
            }
      }
}
4

1 回答 1

0
    TABhs = new CopyOnWriteArraySet(TABhs);
    for(Iterator <PrintWriter> it=TABhs.iterator();it.hasNext();)
    { 
          PrintWriter ot=it.next();
          ot.println("tableupdate#"+tables+"#"+kotno+"#processing");
          ot.flush();
          JOptionPane.showMessageDialog(rootPane, "<html><body>Table Kot Status Changed to <b>Processing</b></body></html>");
    }
于 2013-08-30T06:37:20.260 回答