Results 1 to 2 of 2
  1. #1
    atch is offline Member
    Join Date
    Feb 2010
    Rep Power

    Thumbs down How to get previous element from collection and correctly synchronize threads?

    I'm trying to do something like this:
    Java Code:
    Vector myRays = new Vector<Ray>();
    if (myRays.size() > 0)
                Iterator<Ray> iter = myRays.iterator();
                    if (
                     //myRays.remove(myRays.elementAt(myRays.size()-1));//here I'm getting an error
    I'm getting this error:
    Exception in thread "Thread-5" java.util.ConcurrentModificationException
    at java.util.AbstractList$Itr.checkForComodification

    I suspect that some of my methods should be synchronized (those which has direct access to myRays object) and I've made them synchronized but without any results.
    Thanks for any help.

  2. #2
    r035198x is offline Senior Member
    Join Date
    Aug 2009
    Rep Power


    You cannot modify the list while iterating over it except through the Iterator only.

Similar Threads

  1. how to synchronize a thread
    By sumanandjesus in forum Advanced Java
    Replies: 4
    Last Post: 03-14-2009, 10:26 AM
  2. compare newly added Vector Element with previous elements
    By nidhirastogi in forum Advanced Java
    Replies: 10
    Last Post: 09-10-2008, 01:32 AM
  3. Replies: 0
    Last Post: 04-09-2008, 06:39 PM
  4. How to synchronize threads on an object
    By Java Tip in forum java.lang
    Replies: 0
    Last Post: 04-09-2008, 06:39 PM
  5. Can't synchronize multiple JPanels in a JFrame
    By vassil_zorev in forum AWT / Swing
    Replies: 0
    Last Post: 12-30-2007, 04:22 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts