allujyothirmayi / cloudsim

Automatically exported from code.google.com/p/cloudsim
0 stars 0 forks source link

ConcurrentModificationException in CloudSimExample8 #6

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. In CloudSimExample8, add:
GlobalBroker globalBroker2 = new GlobalBroker("GlobalBroker2"); // in the next 
line of GlobalBroker globalBroker = new GlobalBroker("GlobalBroker");

2.Add:

newList.addAll(globalBroker2.getBroker().getCloudletReceivedList()); // after 
newList.addAll(globalBroker.getBroker().getCloudletReceivedList());

3. Run the class.

What is the expected output? What do you see instead?

The error that you will get is:

java.util.ConcurrentModificationException
        at java.util.TreeMap$PrivateEntryIterator.nextEntry(TreeMap.java:1100)
        at java.util.TreeMap$KeyIterator.next(TreeMap.java:1154)
        at org.cloudbus.cloudsim.core.CloudSim.runClockTick(CloudSim.java:476)
        at org.cloudbus.cloudsim.core.CloudSim.run(CloudSim.java:815)
        at org.cloudbus.cloudsim.core.CloudSim.startSimulation(CloudSim.java:154)
        at org.cloudbus.cloudsim.examples.CloudSimExample8.main(CloudSimExample8.java:139)

Please provide any additional information below.

The error is produced by two Globalbrokers scheduled at the same time, as you 
can see in the method:

@Override
public void startEntity() {
Log.printLine("GlobalBroker is starting...");
schedule(getId(), 200, CREATE_BROKER);
}

Original issue reported on code.google.com by rodrigo.calheiros on 19 Jul 2011 at 12:26

GoogleCodeExporter commented 8 years ago
The problem does not seem to relate to the example or dynamic creation of 
Brokers; instead, it seems to be related to Future queue access in CloudSim 
core.

Original comment by rodrigo.calheiros on 19 Jul 2011 at 4:15

GoogleCodeExporter commented 8 years ago
The problem is caused because startEntity() method sometimes tries to add 
Events to the future queue. Because this queue is being iterated (so the 
dynamic event creation is captured), modification of it (to add the new 
element) is illegal.

A possible solution: postpone execution of startEntity() to a point AFTER 
iteration over the list in CloudSim.runClockTick() (requires major 
modifications in the code) or modifying the send() (and related methods) in 
CloudSim to send these messages to the deferred list (example, by capturing the 
ConcurrentEventModification in these methods and adding events failed to be 
added to future to deferred.

Original comment by rodrigo.calheiros on 19 Jul 2011 at 7:42

GoogleCodeExporter commented 8 years ago

Original comment by rodrigo.calheiros on 15 Dec 2011 at 4:06

GoogleCodeExporter commented 8 years ago
We will postpone solution of this issue for a future release, so we can decide 
if the feature in question (dynamic creation of entities) is really necessary.

Original comment by rodrigo.calheiros on 16 Dec 2011 at 5:52