Fixed thread safety

This commit is contained in:
TheMode 2019-08-10 08:59:33 +02:00
parent d4bf3bd2ec
commit cc203b1a1a
3 changed files with 6 additions and 6 deletions

View File

@ -11,10 +11,9 @@ public class EntityManager {
private Set<LivingEntity> livingEntities = Collections.synchronizedSet(new HashSet<>()); private Set<LivingEntity> livingEntities = Collections.synchronizedSet(new HashSet<>());
private ExecutorService pool = Executors.newFixedThreadPool(5); private ExecutorService pool = Executors.newFixedThreadPool(50);
public void update() { public void update() {
livingEntities.removeIf(livingEntity -> livingEntity.shouldRemove()); livingEntities.removeIf(livingEntity -> livingEntity.shouldRemove());
synchronized (livingEntities) { synchronized (livingEntities) {

View File

@ -11,7 +11,6 @@ public class ChickenCreature extends EntityCreature {
@Override @Override
public void update() { public void update() {
//System.out.println("Update poulet");
onGround = true; onGround = true;
double speed = 0.01; double speed = 0.01;

View File

@ -3,12 +3,14 @@ package fr.themode.minestom.net;
import fr.themode.minestom.entity.Player; import fr.themode.minestom.entity.Player;
import fr.themode.minestom.net.player.PlayerConnection; 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 { public class ConnectionManager {
private Set<PlayerConnection> connections = new HashSet<>(); private volatile Map<PlayerConnection, Player> connectionPlayerMap = new HashMap<>();
private Map<PlayerConnection, Player> connectionPlayerMap = new HashMap<>();
public Player getPlayer(PlayerConnection connection) { public Player getPlayer(PlayerConnection connection) {
return connectionPlayerMap.get(connection); return connectionPlayerMap.get(connection);