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 @Override
public void save() public void save()
{ {
Map<String, String> copy = new HashMap<>();
lock.readLock().lock(); lock.readLock().lock();
try ( FileWriter wr = new FileWriter( file ) ) try
{ {
yaml.dump( data, wr ); copy.putAll( data );
} catch ( IOException ex )
{
ProxyServer.getInstance().getLogger().log( Level.WARNING, "Could not save reconnect locations", ex );
} finally } finally
{ {
lock.readLock().unlock(); 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 @Override