Skip to content

Commit

Permalink
Merge pull request #203 from FlintMC/fix/use-concurrenthashmap-in-cla…
Browse files Browse the repository at this point in the history
…ss-cache

Use ConcurrentHashMap instead of HashMap in DefaultClassCacheIndex
  • Loading branch information
jan-br committed May 28, 2021
2 parents ac226ea + 44fbb86 commit ca0fb4e
Showing 1 changed file with 5 additions and 5 deletions.
Expand Up @@ -28,9 +28,9 @@
import net.flintmc.util.classcache.ClassCacheIndex;
import org.apache.logging.log4j.Logger;
import java.io.*;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;
import java.util.function.BiFunction;

@Singleton
Expand All @@ -57,7 +57,7 @@ private DefaultClassCacheIndex(@InjectLogger Logger logger,
.fromJson(new FileReader(indexFile), IndexModel.class);
this.data.elements.forEach((name, element) -> {
element.setName(name);
element.cachedClasses = new HashMap<>();
element.cachedClasses = new ConcurrentHashMap<>();
});
} catch (FileNotFoundException e) {
this.logger
Expand Down Expand Up @@ -102,7 +102,7 @@ private static class IndexModel {
private final Map<String, IndexElement> elements;

IndexModel() {
this.elements = new HashMap<>();
this.elements = new ConcurrentHashMap<>();
}

IndexElement getOrInsert(String name) {
Expand All @@ -127,9 +127,9 @@ private static class IndexElement {
transient Map<Long, CachedClass> cachedClasses;

IndexElement(String name) {
this.uuids = new HashMap<>();
this.uuids = new ConcurrentHashMap<>();
this.name = name;
this.cachedClasses = new HashMap<>();
this.cachedClasses = new ConcurrentHashMap<>();
}

void setName(String name) {
Expand Down

0 comments on commit ca0fb4e

Please sign in to comment.