Use a defensive copy for shorter lock time

This commit is contained in:
md_5 2013-07-11 11:14:12 +10:00
parent 499337c98e
commit 58ca63e2b1

View File

@ -82,17 +82,23 @@ public class YamlReconnectHandler extends AbstractReconnectManager
@Override
public void save()
{
Map<String, String> 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