Switching HashMap to ConcurrentHashMap to address ConcurrentModificationException on server start

This commit is contained in:
jsownz
2018-06-20 11:12:41 -07:00
parent 2c25a90831
commit 208fdd65b2
3 changed files with 10 additions and 5 deletions

3
.gitignore vendored
View File

@@ -4,6 +4,8 @@
Holocore.iml
out
.idea
.classpath
.project
# Gradle
build
@@ -14,5 +16,6 @@ build
/log/
/cfg/
/odb/
/bin/
*.db
*.iff

View File

@@ -52,6 +52,7 @@ import me.joshlarson.jlcommon.log.Log;
import java.io.File;
import java.io.IOException;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
public class TravelHelper {
@@ -61,7 +62,7 @@ public class TravelHelper {
private final TravelPointManager pointManager;
public TravelHelper() {
this.travel = new HashMap<>();
this.travel = new ConcurrentHashMap<>();
this.travelExecutor = new ThreadPool(3, "travel-shuttles-%d");
this.routeManager = new AllowedRouteManager();
this.pointManager = new TravelPointManager();
@@ -268,11 +269,11 @@ public class TravelHelper {
private final Map<Terrain, Map<Terrain, Integer>> routeCosts;
public AllowedRouteManager() {
this.routeCosts = new HashMap<>();
this.routeCosts = new ConcurrentHashMap<>();
}
public void addRoute(Terrain departure, Terrain destination, int fee) {
Map<Terrain, Integer> departureCosts = routeCosts.computeIfAbsent(departure, k -> new HashMap<>());
Map<Terrain, Integer> departureCosts = routeCosts.computeIfAbsent(departure, k -> new ConcurrentHashMap<>());
departureCosts.put(destination, fee);
}

View File

@@ -33,6 +33,7 @@ import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
public class TravelPointManager {
@@ -40,8 +41,8 @@ public class TravelPointManager {
private final Map<Terrain, List<TravelPoint>> starportPoints;
public TravelPointManager() {
this.shuttlePoints = new HashMap<>();
this.starportPoints = new HashMap<>();
this.shuttlePoints = new ConcurrentHashMap<>();
this.starportPoints = new ConcurrentHashMap<>();
}
public void addTravelPoint(TravelPoint point) {