From cc203b1a1af838bb5793d758e0bde3b7b0017694 Mon Sep 17 00:00:00 2001 From: TheMode Date: Sat, 10 Aug 2019 08:59:33 +0200 Subject: [PATCH] Fixed thread safety --- .../java/fr/themode/minestom/entity/EntityManager.java | 3 +-- .../fr/themode/minestom/entity/demo/ChickenCreature.java | 1 - .../java/fr/themode/minestom/net/ConnectionManager.java | 8 +++++--- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/main/java/fr/themode/minestom/entity/EntityManager.java b/src/main/java/fr/themode/minestom/entity/EntityManager.java index 9d3b83de7..b82f118eb 100644 --- a/src/main/java/fr/themode/minestom/entity/EntityManager.java +++ b/src/main/java/fr/themode/minestom/entity/EntityManager.java @@ -11,10 +11,9 @@ public class EntityManager { private Set livingEntities = Collections.synchronizedSet(new HashSet<>()); - private ExecutorService pool = Executors.newFixedThreadPool(5); + private ExecutorService pool = Executors.newFixedThreadPool(50); public void update() { - livingEntities.removeIf(livingEntity -> livingEntity.shouldRemove()); synchronized (livingEntities) { diff --git a/src/main/java/fr/themode/minestom/entity/demo/ChickenCreature.java b/src/main/java/fr/themode/minestom/entity/demo/ChickenCreature.java index f7261e5c7..37c512844 100644 --- a/src/main/java/fr/themode/minestom/entity/demo/ChickenCreature.java +++ b/src/main/java/fr/themode/minestom/entity/demo/ChickenCreature.java @@ -11,7 +11,6 @@ public class ChickenCreature extends EntityCreature { @Override public void update() { - //System.out.println("Update poulet"); onGround = true; double speed = 0.01; diff --git a/src/main/java/fr/themode/minestom/net/ConnectionManager.java b/src/main/java/fr/themode/minestom/net/ConnectionManager.java index 5c65f5378..fb5526a75 100644 --- a/src/main/java/fr/themode/minestom/net/ConnectionManager.java +++ b/src/main/java/fr/themode/minestom/net/ConnectionManager.java @@ -3,12 +3,14 @@ package fr.themode.minestom.net; import fr.themode.minestom.entity.Player; import fr.themode.minestom.net.player.PlayerConnection; -import java.util.*; +import java.util.Collection; +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; public class ConnectionManager { - private Set connections = new HashSet<>(); - private Map connectionPlayerMap = new HashMap<>(); + private volatile Map connectionPlayerMap = new HashMap<>(); public Player getPlayer(PlayerConnection connection) { return connectionPlayerMap.get(connection);