Concurrency Problem

DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 3 of 3

Thread: Concurrency Problem

  1. #1
    Join Date
    Jan 2007

    Concurrency Problem

    Hi, i have a problem and while i think i do know what it is i cannot work out how to solve it, i am making a Breakout style game just to learn graphics capabilities of SDL and OpenGL in java. I think the problem is in the line, 'block current = (block);', but cannot see how, the error i get is:

    exception at thread main, java.util.ConcurrentModException
    at java.util.LinkedList$ListItr.checkForComodifications(unknown source)
    '' '' '' .next(unknown source)
    at breakout.update(209) --line before the line i thinks the problem

    Any help would be apprieciated

    			//check to see if it collides with our blocks
    			//iteration through the list
    			synchronized (ListHandler.Blocks)
    				ListIterator it = ListHandler.Blocks.listIterator(0);
    				int count = 0;
    				// Go through the list
    				while( it.hasNext() )
    					// Retrieve the next object in the list
    					block current = (block);
    					// Draw it to the screen
    					boolean hit = current.check_ball_collision(our_ball);

  2. #2
    Join Date
    Jan 2007
    Okay problem is in this part:

    I dont understand why..?

  3. #3
    Join Date
    Jul 2004
    I don't really know Java but there were some things I came up with that might be wrong, but what I think is really the problem might be that you are removing nodes from a list that may have more than one children. Why not simply go through the list of Blocks showing the data and then at the end try to remove them?

    The only other way I came up with was a bit messy: instead of going from (0) to the end removing nodes as you go down, start from the end to (0) and remove nodes as you go up:

    Ex: This means that "ListIterator it = ListHandler.Blocks.listIterator(last_node);"

    1. initialize array hit_nodes with length of ListHandler.Blocks //let's say 7
    2. initialize variable len_nodes to length of array hit_nodes or ListHandler.Blocks
    3. loop through ListHandler.Blocks reading data from it and moving to hit_nodes
    4. remove node when finished with it
       for int len_nodes=(ListHandler.Blocks.length)
         loop until len_nodes==0;
           hit_nodes[len_nodes] = ListHandler.Blocks.listIterator(len_nodes); //move data
           ListHandler.Blocks.remove(len_nodes); //now remove node
           len_nodes--; //to reflect new length
    Lastly, go back through from beginning of array showing the data as you go down.
    Last edited by Kerowren; 01-09-2007 at 03:59 PM.
    "Those who would sacrifice liberty for security, deserve neither liberty nor security." -- Benjamin Franklin

Similar Threads

  1. login problem
    By dbrook007 in forum ASP.NET
    Replies: 0
    Last Post: 11-06-2006, 04:54 AM
  2. Replies: 0
    Last Post: 12-13-2001, 12:06 PM
  3. a problem with font and language
    By Roseta in forum VB Classic
    Replies: 0
    Last Post: 11-14-2001, 03:24 AM
  4. Arabic problem view
    By Ayman in forum VB Classic
    Replies: 0
    Last Post: 04-03-2000, 01:08 AM
  5. Problem with CryptoAPI and JCE
    By Jason Bock in forum VB Classic
    Replies: 0
    Last Post: 03-21-2000, 06:48 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
Latest Articles
Questions? Contact us.
Web Development
Latest Tips
Open Source

   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center