在java swing中获取java.util.ConcurrentModificationException

在java swing中获取java.util.ConcurrentModificationException,java,exception,hashset,concurrentmodification,Java,Exception,Hashset,Concurrentmodification,单击按钮多次执行以下代码时获取java.util.ConcurrentModificationException for(Iterator <PrintWriter> it=TABhs.iterator();it.hasNext();) { PrintWriter ot=it.next(); ot.println("tableupdate#"+ta

单击按钮多次执行以下代码时获取
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>");
                    }
for(Iterator it=TABhs.Iterator();it.hasNext();) { PrintWriter ot=it.next(); ot.println(“表格更新”#“+表格+”#“+kotno+”#处理”); ot.flush(); showMessageDialog(根窗格,“表Kot状态更改为处理”); } 有人能告诉我一些解决办法吗

这里TABhs是带有PrintWriter泛型的HashSet

HashSet <PrintWriter> TABhs=new HashSet<PrintWriter>();
HashSet TABhs=newhashset();
按钮单击操作如下所示

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);
            }
      }
}
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt){
String stat=status_combo.getSelectedItem().toString();
String tables=tableno_combo.getSelectedItem().toString();
字符串kotno=kotno_combo.getSelectedItem().toString();
如果(统计等于(“处理”))
{
试一试{
String query=“UPDATE table_orders SET status=”+stat.toLowerCase()+“,其中tableno=”“+tables+”,kotno=”+kotno+”;
int restatus=dbGetDet.insertDetails(query);
如果(restatus>0){
filtercomboBox();
fillTable();
for(Iterator it=TABhs.Iterator();it.hasNext();)
{ 
PrintWriter ot=it.next();
ot.println(“表格更新”#“+表格+”#“+kotno+”#处理”);
ot.flush();
showMessageDialog(根窗格,“表Kot状态更改为处理”);
}
System.out.println(“TABhs----------------->”+TABhs.size());
}
}捕获(例外情况除外){
Logger.getLogger(MYClientclass.class.getName()).log(Level.SEVERE,null,ex);
}
}
}
TABhs=新的CopyOnWriteArraySet(TABhs);
for(Iterator it=TABhs.Iterator();it.hasNext();)
{ 
PrintWriter ot=it.next();
ot.println(“表格更新”#“+表格+”#“+kotno+”#处理”);
ot.flush();
showMessageDialog(根窗格,“表Kot状态更改为处理”);
}

是否有其他线程修改该集?先生,这是什么CopyOnWriteArraySet(),它是线程安全的集实现。获取类似---------的异常找不到符号符号:方法CopyOnWriteArraySet()位置:类kotouch.MyClientClassUpdate在应答中。忘记添加新的。并导入此导入java.util.concurrent.CopyOnWriteArraySet;现在我得到了------所需的不兼容类型:java.util.HashSet找到:java.util.concurrent.CopyOnWriteArraySet
    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>");
    }