title: Threads and Concurrent Modification Exception working with a list
body: <p>I know this is a daft questions but cant work out how to fix this, I have not had much experience with using threads before.</p>
  
  <p>Below should create first of all a timer which will execute the command output.write(mylist) every 10 seconds which will simply output the contents of mylist.</p>
  
  <p>Secondly it loops through about 3 lists I have and for each them creates a thread which will continue to loop through getting the next word in the list.
  Please note: this is stripped down version and not complete so please don't comment on the arraylist / list but rather the error itself.</p>
  
  <p>There is a concurrent modification exception happening frequently but not all the time when it tries to do <code>output.write()</code>.  I am guessing this is because one of the other threads are currently saving something to <code>mylist</code>? How would I go about fixing this?</p>
  
  <pre><code>    Runnable timer = new Runnable() {
          public void run() {
              try {
                  while (true) {
                      Thread.sleep(10000);
                      output.write(mylist);
                  }
              } catch (InterruptedException iex) {}
          }
      };
      Thread timerThread = new Thread(timer);
      timerThread.start();
  
      for (final ValueList item : list) {
  
          Runnable r = new Runnable() {
              public void run() {
                  try {
                      while (true) {
  
                          char curr = item.getNext();
  
                           mylist.addWord(curr);
                      }
                  } catch (InterruptedException iex) {}
              }
          };
  
          Thread thr = new Thread(r);
          thr.start();
      }
  }
  </code></pre>