Skip to content

Commit 191c5c9

Browse files
committed
make cancelling of individual tags thread-safe
1 parent 61da810 commit 191c5c9

1 file changed

Lines changed: 12 additions & 10 deletions

File tree

library/src/main/java/com/proxerme/library/connection/ProxerConnection.java

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,8 @@ public String id() {
7575
}
7676
};
7777

78-
private static Handler handler = new Handler(Looper.getMainLooper());
79-
private static ConcurrentLinkedQueue<ParseThread> parseThreads = new ConcurrentLinkedQueue<>();
78+
private static final Handler handler = new Handler(Looper.getMainLooper());
79+
private static final ConcurrentLinkedQueue<ParseThread> parseThreads = new ConcurrentLinkedQueue<>();
8080

8181
/**
8282
* Entry point to load News of a specified page.
@@ -132,18 +132,20 @@ public static ConferencesRequest loadConferences(@IntRange(from = 1) int page) {
132132
* @see ProxerTag
133133
*/
134134
public static void cancel(@ConnectionTag int tag) {
135-
Iterator<ParseThread> iterator = parseThreads.iterator();
135+
synchronized (parseThreads) {
136+
Iterator<ParseThread> iterator = parseThreads.iterator();
136137

137-
while (iterator.hasNext()) {
138-
ParseThread current = iterator.next();
138+
while (iterator.hasNext()) {
139+
ParseThread current = iterator.next();
139140

140-
if (current.getTag() == tag) {
141-
current.interrupt();
142-
iterator.remove();
141+
if (current.getTag() == tag) {
142+
current.interrupt();
143+
iterator.remove();
144+
}
143145
}
144-
}
145146

146-
Bridge.cancelAll().tag(String.valueOf(tag)).commit();
147+
Bridge.cancelAll().tag(String.valueOf(tag)).commit();
148+
}
147149
}
148150

149151
/**

0 commit comments

Comments
 (0)