Thread: [PI]on logout method error[PI]

Results 1 to 5 of 5
  1. #1 [PI]on logout method error[PI] 
    I heal clients


    Join Date
    Apr 2013
    Posts
    680
    Thanks given
    65
    Thanks received
    239
    Rep Power
    108
    i got this error when i try to logout : -
    Code:
    [1/11/14 11:03 AM]: Game saved for player Cody
    [1/11/14 11:03 AM]: [DEREGISTERED]: Cody
    [1/11/14 11:03 AM]: java.util.ConcurrentModificationException
    [1/11/14 11:03 AM]: 	at java.util.ArrayList$Itr.checkForComodification(Unknown Source)
    [1/11/14 11:03 AM]: 	at java.util.ArrayList$Itr.next(Unknown Source)
    [1/11/14 11:03 AM]: 	at server.event.cycle.CycleEventHandler.stopEvents(CycleEventHandler.java:60)
    [1/11/14 11:03 AM]: 	at server.model.players.Client.destruct(Client.java:148)
    [1/11/14 11:03 AM]: 	at server.model.players.PlayerHandler.removePlayer(PlayerHandler.java:284)
    [1/11/14 11:03 AM]: 	at server.model.players.PlayerHandler.process(PlayerHandler.java:129)
    [1/11/14 11:03 AM]: 	at server.Server$1.execute(Server.java:128)
    [1/11/14 11:03 AM]: 	at server.event.Task.tick(Task.java:103)
    [1/11/14 11:03 AM]: 	at server.event.TaskScheduler.run(TaskScheduler.java:98)
    [1/11/14 11:03 AM]: 	at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source)
    [1/11/14 11:03 AM]: 	at java.util.concurrent.FutureTask.runAndReset(Unknown Source)
    [1/11/14 11:03 AM]: 	at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(Unknown Source)
    [1/11/14 11:03 AM]: 	at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(Unknown Source)
    [1/11/14 11:03 AM]: 	at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
    [1/11/14 11:03 AM]: 	at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    [1/11/14 11:03 AM]: 	at java.lang.Thread.run(Unknown Source)
    my CycleEventHandler.java
    Code:
    package server.event.cycle;
    
    import java.util.ArrayList;
    import java.util.List;
    
    /**
     * Handles all of our cycle based events
     * 
     * @author Stuart <RogueX>
     * @author Null++
     * 
     */
    public class CycleEventHandler {
    
    	private static CycleEventHandler instance;
    
    	public static CycleEventHandler getSingleton() {
    		if (instance == null) {
    			instance = new CycleEventHandler();
    		}
    		return instance;
    	}
    
    	private List<CycleEventContainer> events;
    
    	public CycleEventHandler() {
    		this.events = new ArrayList<CycleEventContainer>();
    	}
    
    	public void addEvent(int id, Object owner, CycleEvent event, int cycles) {
    		this.events.add(new CycleEventContainer(id, owner, event, cycles));
    	}
    
    	public void addEvent(Object owner, CycleEvent event, int cycles) {
    		this.events.add(new CycleEventContainer(-1, owner, event, cycles));
    	}
    
    	public void process() {
    		List<CycleEventContainer> eventsCopy = new ArrayList<CycleEventContainer>(events);
    		List<CycleEventContainer> remove = new ArrayList<CycleEventContainer>();
    		for (CycleEventContainer c : eventsCopy) {
    			if (c != null) {
    				if (c.needsExecution())
    					c.execute();
    				if (!c.isRunning()) {
    					remove.add(c);
    				}
    			}
    		}
    		for (CycleEventContainer c : remove) {
    			events.remove(c);
    		}
    	}
    	
    	public int getEventsCount() {
    		return this.events.size();
    	}
    	
    	public void stopEvents(Object owner) {
    		for (CycleEventContainer c : events) {
    			if(c.getOwner() == owner) {
    				c.stop();
    			}
    		}
    	}
    	
    	public void stopEvents(Object owner, int id) {
    		for (CycleEventContainer c : events) {
    			if(c.getOwner() == owner && id == c.getID()) {
    				c.stop();
    			}
    		}
    	}
    	
    	public void stopEvents(int id) {
    		for (CycleEventContainer c : events) {
    			if(id == c.getID()) {
    				c.stop();
    			}
    		}
    	}
    }
    my logout method on client class : -
    Code:
    	public void logout() {
    		if (System.currentTimeMillis() - logoutDelay > 10000) {
    			CycleEventHandler.getSingleton().stopEvents(this);
    			outStream.createFrame(109);
    			properLogout = true;
    		} else {
    			sendMessage("You must wait a few seconds from being out of combat to logout.");
    		}
    	}
    my removeplayer method
    Code:
    	private void removePlayer(Player plr) {
    		if (plr.privateChat != 2) {
    			for (int i = 1; i < GameConfig.MAX_PLAYERS; i++) {
    				if (players[i] == null || players[i].isActive == false)
    					continue;
    				Client o = (Client) PlayerHandler.players[i];
    				if (o != null) {
    					PlayerAssistant.updatePM(o, plr.playerId, 0);
    				}
    			}
    		}
    		plr.destruct();
    	}
    NO ONE IS PERFECT
    "No one in this world is pure and perfect, if you avoid people for their little mistakes you will be always alone in this world, so judge less and love more."
    "Ship in the harbor is safe, but that is not what ships are built for."
    Reply With Quote  
     

  2. #2  
    Registered Member
    TheChosenOne's Avatar
    Join Date
    Jan 2013
    Posts
    967
    Thanks given
    47
    Thanks received
    161
    Rep Power
    366
    I'm not too sure but I suspect it has to do something with the .stop() code of a CycleEventContainer to remove the container from the events list while it's being iterated.
    Have a read-through of this: How to Avoid ConcurrentModificationException when using an Iterator
    It's helped me out a couple of times.
    Reply With Quote  
     

  3. #3  
    I heal clients


    Join Date
    Apr 2013
    Posts
    680
    Thanks given
    65
    Thanks received
    239
    Rep Power
    108
    bump
    NO ONE IS PERFECT
    "No one in this world is pure and perfect, if you avoid people for their little mistakes you will be always alone in this world, so judge less and love more."
    "Ship in the harbor is safe, but that is not what ships are built for."
    Reply With Quote  
     

  4. #4  
    Banned [PI]on logout method error[PI] Market Banned


    Join Date
    Jan 2011
    Age
    26
    Posts
    3,112
    Thanks given
    1,198
    Thanks received
    1,479
    Rep Power
    0
    Cycle events suck. You'd be better off designing your own task system.


    A CurrentModificationException is thrown if you try and modify a list while its being iterated over. Example:


    Code:
    for(Task t : this.getTasks()) {
         t.run();
         this.getTasks().remove(t); // would throw a CurrentModificationException because you are modifying the list while its 
                                    // being iterated over. Use a raw iterator to remove the element instead. 
    }
    for example

    Code:
    for(Iterator<Task> iter = this.getTasks().iterator(); iter.hasNext();) {
         Task t = iter.next();
    
         t.run();
         iter.remove(); // would not throw a CurrentModificationException, but is doing the exact same thing as the above code. 
    }
    Reply With Quote  
     

  5. #5  
    Renown Programmer & Respected Member

    Ryley's Avatar
    Join Date
    Aug 2011
    Posts
    596
    Thanks given
    254
    Thanks received
    521
    Rep Power
    1332
    Wow that code really sucks. I don't see the need to create two more lists to store old events and events to be removed, that is just plain retarded. Also I don't see the point with the 3 stop methods but whatever. Here's your fixed code. Wrote in reply box so bare with it.

    Code:
    package server.event.cycle;
    
    import java.util.ArrayList;
    import java.util.Iterator;
    import java.util.List;
    
    /**
     * Handles all of our cycle based events
     * 
     * @author Stuart <RogueX>
     * @author Null++
     * 
     */
    public class CycleEventHandler {
    
    	private static CycleEventHandler instance;
    
    	public static CycleEventHandler getSingleton() {
    		if (instance == null) {
    			instance = new CycleEventHandler();
    		}
    		return instance;
    	}
    
    	private List<CycleEventContainer> events;
    
    	public CycleEventHandler() {
    		this.events = new ArrayList<CycleEventContainer>();
    	}
    
    	public void addEvent(int id, Object owner, CycleEvent event, int cycles) {
    		this.events.add(new CycleEventContainer(id, owner, event, cycles));
    	}
    
    	public void addEvent(Object owner, CycleEvent event, int cycles) {
    		this.events.add(new CycleEventContainer(-1, owner, event, cycles));
    	}
    
    	public void process() {
    		Iterator<CycleEventContainer> iterator = events.iterator();
    		while(iterator.hasNext()) {
    			CycleEventContainer container = iterator.next();
    			if(!container.isRunning()) {
    				iterator.remove();
    				continue;
    			}
    			if(container.needsExecution()) {
    				container.execute();
    			}
    		}
    	}
    
    	public int getEventsCount() {
    		return this.events.size();
    	}
    
    	public void stopEvents(Object owner) {
    		for (CycleEventContainer c : events) {
    			if(c.getOwner() == owner) {
    				c.stop();
    			}
    		}
    	}
    	
    	public void stopEvents(Object owner, int id) {
    		for (CycleEventContainer c : events) {
    			if(c.getOwner() == owner && id == c.getID()) {
    				c.stop();
    			}
    		}
    	}
    	
    	public void stopEvents(int id) {
    		for (CycleEventContainer c : events) {
    			if(id == c.getID()) {
    				c.stop();
    			}
    		}
    	}
    }
    The problem was that you were attempting to modify the list while you were iterating over it, which by definition cannot be done concurrently
    Reply With Quote  
     


Thread Information
Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)


User Tag List

Similar Threads

  1. Messed up on RunServer CMD Error PI
    By Jay Gatsby in forum Help
    Replies: 3
    Last Post: 07-24-2013, 09:25 PM
  2. [PI] on client startup error
    By EricFtw in forum Help
    Replies: 8
    Last Post: 05-07-2012, 07:48 PM
  3. [PI] ::checkinv command 1 error [PI]
    By lancer in forum Help
    Replies: 5
    Last Post: 05-09-2011, 11:32 AM
  4. [PI] Help please CMD error. [PI]
    By xpvpxx in forum Help
    Replies: 3
    Last Post: 01-19-2011, 07:38 PM
  5. [PI] Dragon Claws, Animation Error [PI]
    By Kickyamom in forum Help
    Replies: 6
    Last Post: 01-16-2011, 06:21 AM
Posting Permissions
  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •