Browse Source

Fix concurrent modification exception

Olyol95 8 years ago
parent
commit
c9e91a56c2
1 changed files with 10 additions and 1 deletions
  1. 10 1
      src/org/noip/olyol95/googlr/QueryCache.java

+ 10 - 1
src/org/noip/olyol95/googlr/QueryCache.java

@@ -2,6 +2,7 @@ package org.noip.olyol95.googlr;
 
 import org.bukkit.scheduler.BukkitRunnable;
 
+import java.sql.Array;
 import java.util.ArrayList;
 import java.util.Hashtable;
 
@@ -51,9 +52,17 @@ public class QueryCache {
         @Override
         public void run() {
 
+            ArrayList<Integer> toRemove = new ArrayList<>();
+
             for (Integer hash: cache.keySet()) {
 
-                if (cache.get(hash).isExpired(300000)) cache.remove(hash);
+                if (cache.get(hash).isExpired(300000)) toRemove.add(hash);
+
+            }
+
+            for (Integer hash: toRemove) {
+
+                cache.remove(hash);
 
             }