У меня есть базовые знания Java, и в настоящее время я работаю над кодом на основе Java.
РЕДАКТИРОВАТЬ: я не писал код
Я перебираю отсортированную древовидную карту Event
объектов и получаю это исключение, когда пытаюсь получить следующий элемент:
java.util.ConcurrentModificationException
at java.util.TreeMap$PrivateEntryIterator.nextEntry(Unknown Source)
at java.util.TreeMap$KeyIterator.next(Unknown Source)
Я думаю, это должно быть связано с существованием нескольких записей с одинаковым значением, которые объединены компаратором итератора (имеется в виду это вопрос, но я не знаю, как найти ключи, используемые в компараторе. Объект Event
имеет много параметров (например, идентификатор, время и т. д.), но не уверен какой из них используется для итератора.
Вот соответствующая часть кода (исключение во втором SimEvent first = fit.next();
):
if (future.size() > 0) {
List<SimEvent> toRemove = new ArrayList<SimEvent>();
Iterator<SimEvent> fit = future.iterator();
queue_empty = false;
SimEvent first = fit.next();
processEvent(first);
future.remove(first);
fit = future.iterator();
// Check if next events are at same time...
boolean trymore = fit.hasNext();
while (trymore) {
SimEvent next = fit.next();
if (next.eventTime() == first.eventTime()) {
processEvent(next);
toRemove.add(next);
trymore = fit.hasNext();
} else {
trymore = false;
}
}
future.removeAll(toRemove);
} else {...}
РЕДАКТИРОВАТЬ: Код зала класса future
:
public class FutureQueue {
/** The sorted set. */
private final SortedSet<SimEvent> sortedSet = new TreeSet<SimEvent>();
/** The serial. */
private long serial = 0;
/**
* Add a new event to the queue. Adding a new event to the queue preserves the temporal order of
* the events in the queue.
*
* @param newEvent The event to be put in the queue.
*/
public void addEvent(SimEvent newEvent) {
newEvent.setSerial(serial++);
sortedSet.add(newEvent);
}
/**
* Add a new event to the head of the queue.
*
* @param newEvent The event to be put in the queue.
*/
public void addEventFirst(SimEvent newEvent) {
newEvent.setSerial(0);
sortedSet.add(newEvent);
}
/**
* Returns an iterator to the queue.
*
* @return the iterator
*/
public Iterator<SimEvent> iterator() {
return sortedSet.iterator();
}
/**
* Returns the size of this event queue.
*
* @return the size
*/
public int size() {
return sortedSet.size();
}
/**
* Removes the event from the queue.
*
* @param event the event
* @return true, if successful
*/
public boolean remove(SimEvent event) {
return sortedSet.remove(event);
}
/**
* Removes all the events from the queue.
*
* @param events the events
* @return true, if successful
*/
public boolean removeAll(Collection<SimEvent> events) {
return sortedSet.removeAll(events);
}
public void clear() {
sortedSet.clear();
}
}
Любое предложение о том, как приступить к отладке этой проблемы?
future
? - person Vasiliy Vlasov   schedule 07.06.2017