From 58ca63e2b148a7b6b2771cd73104b170b198c27b Mon Sep 17 00:00:00 2001 From: md_5 Date: Thu, 11 Jul 2013 11:14:12 +1000 Subject: [PATCH] Use a defensive copy for shorter lock time --- .../bungee/reconnect/YamlReconnectHandler.java | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/proxy/src/main/java/net/md_5/bungee/reconnect/YamlReconnectHandler.java b/proxy/src/main/java/net/md_5/bungee/reconnect/YamlReconnectHandler.java index ca05aaf6..d2660fc0 100644 --- a/proxy/src/main/java/net/md_5/bungee/reconnect/YamlReconnectHandler.java +++ b/proxy/src/main/java/net/md_5/bungee/reconnect/YamlReconnectHandler.java @@ -82,17 +82,23 @@ public class YamlReconnectHandler extends AbstractReconnectManager @Override public void save() { + Map copy = new HashMap<>(); lock.readLock().lock(); - try ( FileWriter wr = new FileWriter( file ) ) + try { - yaml.dump( data, wr ); - } catch ( IOException ex ) - { - ProxyServer.getInstance().getLogger().log( Level.WARNING, "Could not save reconnect locations", ex ); + copy.putAll( data ); } finally { lock.readLock().unlock(); } + + try ( FileWriter wr = new FileWriter( file ) ) + { + yaml.dump( copy, wr ); + } catch ( IOException ex ) + { + ProxyServer.getInstance().getLogger().log( Level.WARNING, "Could not save reconnect locations", ex ); + } } @Override