1
0
Fork 0
mirror of https://github.com/geometer/FBReaderJ.git synced 2025-10-04 10:19:33 +02:00

fixed concurrent modification problem

This commit is contained in:
Nikolay Pultsin 2011-04-17 00:10:09 +01:00
parent 0fc36c00ec
commit 1c0251070f

View file

@ -89,9 +89,11 @@ public class NetworkLibrary {
public List<String> languageCodes() { public List<String> languageCodes() {
final TreeSet<String> languageSet = new TreeSet<String>(); final TreeSet<String> languageSet = new TreeSet<String>();
synchronized (myLinks) {
for (INetworkLink link : myLinks) { for (INetworkLink link : myLinks) {
languageSet.add(link.getLanguage()); languageSet.add(link.getLanguage());
} }
}
return new ArrayList<String>(languageSet); return new ArrayList<String>(languageSet);
} }
@ -245,7 +247,11 @@ public class NetworkLibrary {
} }
} }
} }
for (INetworkLink link : myLinks) { final List<INetworkLink> linksCopy;
synchronized (myLinks) {
linksCopy = new ArrayList<INetworkLink>(myLinks);
}
for (INetworkLink link : linksCopy) {
if (link instanceof ICustomNetworkLink) { if (link instanceof ICustomNetworkLink) {
final ICustomNetworkLink customLink = (ICustomNetworkLink)link; final ICustomNetworkLink customLink = (ICustomNetworkLink)link;
if (customLink.isObsolete(12 * 60 * 60 * 1000)) { // 12 hours if (customLink.isObsolete(12 * 60 * 60 * 1000)) { // 12 hours
@ -483,6 +489,7 @@ public class NetworkLibrary {
if (id == ICustomNetworkLink.INVALID_ID) { if (id == ICustomNetworkLink.INVALID_ID) {
addLinkInternal(link); addLinkInternal(link);
} else { } else {
synchronized (myLinks) {
for (int i = myLinks.size() - 1; i >= 0; --i) { for (int i = myLinks.size() - 1; i >= 0; --i) {
final INetworkLink l = myLinks.get(i); final INetworkLink l = myLinks.get(i);
if (l instanceof ICustomNetworkLink && if (l instanceof ICustomNetworkLink &&
@ -492,6 +499,7 @@ public class NetworkLibrary {
} }
} }
} }
}
NetworkDatabase.Instance().saveCustomLink(link); NetworkDatabase.Instance().saveCustomLink(link);
invalidateChildren(); invalidateChildren();
} }