目的:高级计算机网络大作业--router(JAVA)
出错功能块:定时向邻居router发送Hello包
异常:
Exception in thread "Timer-1" java.util.ConcurrentModificationException
at java.util.HashMap$HashIterator.nextEntry(Unknown Source)
at java.util.HashMap$EntryIterator.next(Unknown Source)
at java.util.HashMap$EntryIterator.next(Unknown Source)
at bit.cher.router.Router$2.run(Router.java:191)
at java.util.TimerThread.mainLoop(Unknown Source)
at java.util.TimerThread.run(Unknown Source)
报错位置:
都是在it.next()引用迭代器的位置 (实际错误并不是该行代码的问题)
实际错误行:
38 neighbors .remove(neighborId);
58 rt.completeRouteTable .remove((Integer)map.getKey());
错误原因:
当集合A已经生成过iterator it之后,若要对此集合进行操作,只能访问it,不能够再次直接引用A
38 neighbors已经生成过迭代器iSet,应该引用iSet而不能够再次引用 neighbors
58 同理, rt.completeRouteTable已经有迭代器routeIt,应使用 routeIt进行remove
改正结果:
38->35 iS et. remove();
58->59 routeIt. remove();
出错源代码:
修改后源代码: